简体   繁体   English

模式在 angular2 中不起作用

[英]pattern is not working in angular2

我正在通过模式属性实现验证,但它不起作用。

 <input type="text"  formControlName="mobile" name="mobile" pattern="[0-9]" /> 

Use this pattern for mobile number.将此模式用于手机号码。

<input type="text" name="mobile" ng-pattern="/\d{10}/" />

Or you can use this或者你可以使用这个

Mobile Number :
<input type="text" class="form-control" ng-model="mobileNo" name="mobileNo" ng-pattern="regEx" />

JavaScript JavaScript

$scope.regEx="/^[0-9]{10,10}$/;"

If you want to made it work with pattern attribute then如果你想让它与模式属性一起工作,那么

<input type="text" pattern="[789][0-9]{9}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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