简体   繁体   中英

Regular Expression in angular js

I want a ng-pattern expression to validate textbox which 'Should not accept Only Numeric or Special character. It should have at least one alphabet with numeric and special character' in angular js. Example: 1) a1234$ It is acceptable 2) 123%% It is not acceptable 3) abc It is acceptable 4) 56456a It is acceptable 5)123$%^abc It is acceptable

Above scenario should be validate.

Thanks.

Put the hyphen at the end of your character class. When it is the last character it is assumed as a literal hyphen. For example: /^[a-zA-Z-]*$/

<form name="myForm">
   <input type="text" ng-pattern="/^[a-zA-Z-]*$/" ng-model="" name="">
</form>

You can do these checks using positive look ahead assertions. use that regex in ng-pattern

^(?=.*[A-Z])(?=.*[!@#$&*])(?=.*[0-9])(?=.*[a-z].)$

http://www.rubular.com/r/UAwoaPM0Ji

^                         Start anchor
(?=.*[A-Z].)              Ensure string has one uppercase letters.
(?=.*[!@#$&*])            Ensure string has one special case letter.
(?=.*[0-9].)              Ensure string has one digits.
(?=.*[a-z].)              Ensure string has one lowercase letters.
$                         End anchor.


You Can use this code as per your requirement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM