-1

How can I validate emailid and mobile no both in a single input box in AngulaJS?

I'm trying to validate emaild and mobile no in same input box. it is working fine seperately, but for both emaild and mobile it doesn't work.

Natalie Hedström
  • 2,607
  • 3
  • 25
  • 36
jay
  • 1

1 Answers1

0

If you wish to verify the input using AngularJS (not the safest way to do it if it's the only check, making a second check in PHP/back-end/server side is recommanded).

You can use regular expression to filter the email and the phone number. You might want to check out ng-pattern

AngularJS Official documentation page

Emails and AngularJS: https://docs.angularjs.org/api/ng/input/input%5Bemail%5D Example: https://jsfiddle.net/txtuz2xn/4/

Phone number will vary from a country to another. Up to you to see how you want your regex to go.

If you want to have 1 input that checks either the phone or the email you could set up $scope.regex1 = ... and $scope.regex2 = ... and check regex2 if regex1 fails.

Jean Henry
  • 436
  • 4
  • 14
  • Jean as you said I tired with $scope.regex1 and $scope.regex2 .But it is validating only once for email or mobile no .When after writing email I am using backspace button to delete it and write mobile no its not working .How can i fixed that?? There is no backspace event in angular .. – jay Jan 22 '16 at 06:14