[英]looking for a regular expression to match specific decimal format in ng-pattern
[英]regular expresstion to match [/ , .] in ng-pattern
我正在尝试创建一个表达式,以便输入字符串不得包含正斜杠,逗号或点。
<form name="myForm">
<div class="col-sm-4">
<input class="form-control"
type="text"
data-ng-model="model_name"
name="modelName"
ng-pattern="/^[\/,.]/" required>
<div ng-messages="myForm.$submitted && myForm.modelName.$error" role="alert">
<div class="alert alert-danger" ng-message="pattern">Special characters [/ , .] are not allowed.</div>
<div class="alert alert-danger" ng-message="required">This field is required.</div>
</div>
</div>
</form>
正则表达式/^[\\/,.]/
正确匹配方括号内的所有字符,但是问题在于它不允许我输入普通字符串,例如abc或abc_def或任何其他字符串。 我对正则表达式没有很深的了解,我也不知道如何解决此问题。 请帮忙。
您的regex
是错误的, ^
必须位于[]
内才能匹配/.,
以外的所有字符/.,
将它们放在regex中的[^/.,]
中,当在块中使用^
时, []
会匹配除内部内容以外的任何字符[]
。
在测试正则表达式时,此网站非常有用: http : //www.regexpal.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.