rish rish - 1 year ago 63
AngularJS Question

Starting with Number and Ending with Character in Angular JS

I just started learning AngularJs So sorry for dump question. I have requirement to validate the field which will start with number and end with 'M' character eg:- 10M, 5M, 200M etc. please any one help me how to do it in angular js.

Answer Source

You can use ng-pattern in your input field e.g.

<input type="text" ng-model="model" id="input" name="input" ng-pattern="regex" />

and in your controller define regex as

$scope.regex = '\\d+M';

And you can check in your html, if input is valid or not like this:

input valid? = <code>{{form.input.$valid}}</code>

This will work well with ng-messages directive for form validation.

Read More.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download