【问题标题】:grails's validation-mobile,email seems to not workgrails 的验证移动,电子邮件似乎不起作用
【发布时间】:2014-10-21 01:57:44
【问题描述】:

我有一个域类,它有两个属性,使用电子邮件,通过 grails 进行移动验证,类似代码

strMobile attributes:[cn: "mobile", mobile:true]
strEmail  attributes:[cn: "email", email:true],nullable: true

然后我设置

strMobile="abc1111",strEmail="111111", 

执行验证方法,但没有返回

strMobile,strEmail'Error.

是 grails 验证错误还是我做错了什么?

【问题讨论】:

    标签: validation grails groovy


    【解决方案1】:

    您应该在约束关闭中使用移动匹配,因为没有可用于移动的内置约束(据我所知)。对于电子邮件,您可以使用 email:true 之类的:

    static constraints = {
       email nullable: true, email: true
       strMobile matches: "44[0-9]{10}" //Change Matcher As Per Your Requirement
    }
    

    【讨论】:

    • 如果没有可用于移动的内置约束,则无法使用移动约束,只需使用匹配即可。
    • 如果需要,您可以使用github.com/ataylor284/grails-phonenumbers 插件进行电话号码验证。
    猜你喜欢
    • 1970-01-01
    • 2022-06-12
    • 1970-01-01
    • 1970-01-01
    • 2017-05-27
    • 2012-08-19
    • 2019-01-01
    • 2015-01-20
    • 1970-01-01
    相关资源
    最近更新 更多