正则表达式总结

官网介绍

  1. ng-pattern="/^[0-9]+(.[0-9])?$/" 只允许小数点后一位的数字

  2. ng-pattern="/^+?[1-9]*d$/" 只能是整数

  3. ng-pattern="/^[0-9]+(.d+)$/" 必须是小数

  4. ng-pattern='/^[0-9]*$/' 只能是数字

  5. ng-pattern='/^[0-9]{0,4}(\.[0-9]{0,6})?$/' 小数点前最多4位,后最多6位(经纬度)

  6. ng-pattern='/^(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*(),.])[da-zA-Z~!@#$%^&*(),.]{6,}$/'  必须包括数字/小写字母/大写字母/特殊符号,且没有顺序

  7. ngPattern动态定义正则表达式,js中定义self.textlat = '[0-9]{0,4}(\.[0-9]{0,6})?'(不需要开头/^和结尾$/),html中 ng-pattern='$ctrl.textlat'

  8. ng-pattern="/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/"      管理员账号必须为邮箱地址

  9. ng-pattern="/^[0-9a-zA-Z ]{0,20}$/"  必须在20个字符以内,仅限字母、数字、空格

原文地址:https://www.cnblogs.com/maoyazhi/p/6764252.html