0

I have a text box and Search Button in UI. I want to validate it like only Numbers should be entered on button click.

I didn't use it in Form(I got to know lot of ways to validate form control). But simply i've designed it(independent) in my div.

So can you pls guide me to validate my control in Angular.

 <div id="srchbox">
                <p id="ptext">Please enter the Movie Id</p>
                <input type="text" class="form-control" placeholder="Search" id="Srchtxt" ng-model="_Id">
                <button type="submit" class="btn btn-default" id="btnsrch" ng-click="search(_Id)"><span class="glyphicon glyphicon-search"></span></button>
        </div>
1
  • Can you share some code with us? (plunkr,jsfiddle ...) Commented Apr 1, 2015 at 14:17

1 Answer 1

2

Use ngPattern directive.

From documentation

Sets pattern validation error key if the ngModel value does not match a RegExp found by evaluating the Angular expression given in the attribute value. If the expression evaluates to a RegExp object then this is used directly. If the expression is a string then it will be converted to a RegExp after wrapping it in ^ and $ characters. For instance, "abc" will be converted to new RegExp('^abc$').

<input type="text" ng-model="myVariable" ng-pattern="" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.