下拉以通过angularjs验证进行验证 [英] drop down to be validated with angularjs validation

查看:156
本文介绍了下拉以通过angularjs验证进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是角度js的新手,我想用角度js验证验证下拉菜单,你能不能给我一些正则表达式验证的例子,比如电话号码包含至少10位数字

并下拉到在我的页面中验证是这样的



 <  选择   名称  =  AddRoles    id   =  AddRoles   < span class =code-attribute> class   =  form-control      ng-model   =  AddRoles    ng -options   =  item as item.Name for RolesData >  
< 选项 value = > - 选择 - < / option >
< / select >

解决方案

< blockquote>对于正则表达式部分,您可以开始查看 MDN:JavaScript正则表达式 [ ^ ]

此处还有正则表达式信息 [ ^ ]



拥有一个可以以可视方式测试表达式的工具也很有用。我自己使用这个应用程序 RegexTest [ ^ ],但还有其他一些,包括在线工具。



所有这些都说,这里是正则表达式的一个小例子,它将匹配至少10位数的电话号码。

 ^ [0-9] {10,} 






 ^ \d {10,} 






[更新]

将ng-pattern属性添加到输入标签。

 <  选择    name   =  AddRoles    id   =  AddRoles    class   =  form-control    ng-model   =  AddRoles  

ng-pattern = digitsPattern ng-options = item as item.Name for RolesData >
< 选项 价值 = > - 选择 - < / option >
< / select >



和要在Angular模块中添加的变量。

 


I am new to angular js and i want to validate drop down with angular js validation and can u please give me examples for regular expression validation like phone number contains atleast 10 digits
and drop down to be validted is like this in my page

 <select name="AddRoles" id="AddRoles" class="form-control"  ng-model="AddRoles" ng-options="item as item.Name for item in RolesData">
<option value="">-- choose --</option>
 </select>

解决方案

For the regular expression part you can start to look here MDN: JavaScript Regular Expressions[^]
And also here Regular Expression Info[^]

It is also useful to have a tool where you can test expressions in a visual way. I use this application myself RegexTest[^], but there are others as well, including online tools.

All that said, here is a small example of a regular expression that will match phone numbers with at least 10 digits.

^[0-9]{10,}



or

^\d{10,}




[UPDATE]
Add the ng-pattern property to your input tag.

<select name="AddRoles" id="AddRoles" class="form-control" ng-model="AddRoles"

ng-pattern="digitsPattern" ng-options="item as item.Name for item in RolesData">
    <option value="">-- choose --</option>
</select>


And the variable to add inside the Angular module.


这篇关于下拉以通过angularjs验证进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆