我想验证 grails 中的手机号码,手机号码必须以特定数字开头,例如 9

i want to validate the mobile number in grails and the mobile number must start with specific digit like 9

我想检查 grails 中的手机号码验证?手机号码必须以第一个特定数字开头 9.if 它以任何其他号码开头然后用户必须收到消息以输入以以下开头的号码9.

您可以针对此要求使用 matches 约束,例如:

class Mobi {

long mobileNo

static constraints = {
mobileNo(blank:false, matches:"9[0-9]{10}")
 }
}

然后在message.properties中设置您的消息。