大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – Rails验证full_name,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
> Jan Levinson-Gould女士
>马丁·路德·金博士
> Brett d’Arras-d’Haudracey
>布鲁诺
而不是验证那里的字符,您可能只想确保一些字符集不存在.
例如:
class User < ActiveRecord::Base validates_format_of :full_name,:with => /\A[^0-9`!@#\$%\^&*+_=]+\z/ # add any other characters you'd like to disallow inside the [ brackets ] # metacharacters [,\,^,$,.,|,?,*,+,(,and ) need to be escaped with a \ end
测试
@H_722_15@ms. Jan Levinson-Gould # pass Dr. MarTin Luther King,Jr. # pass Brett d'Arras-d'Haudracey # pass Brüno # pass John Doe # pass Mary-Jo Jane Sally Smith # pass Fatty Mc.Error$ # fail FA!L # fail #arold Newm@n # fail N4m3 w1th numb3r5 # fail正则表达式解释
NODE EXPLANATION -------------------------------------------------------------------------------- \A the beginning of the String -------------------------------------------------------------------------------- [^`!@#\$%\^&*+_=\d]+ any character except: '`','!','@','#','\$','%','\^','&','*','+','_','=',digits (0-9) (1 or more times (matching the most amount possiblE)) -------------------------------------------------------------------------------- \z the end of the String
以上是大佬教程为你收集整理的ruby-on-rails – Rails验证full_name全部内容,希望文章能够帮你解决ruby-on-rails – Rails验证full_name所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。