ruby 常用正则表达式

ruby 常用正则表达式

IP

validates_format_of       :ip, :with => /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/

reg = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
 @ip.errors.add(:ip,”格式不正确。”) if !reg.match(@ip.ip)

 

validates_format_of       :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :if => :email?

 

(function($){ $.fn.validationEngineLanguage = function(){ }; $.validationEngineLanguage = { newLang: function(){ //Some regular expressions were append "|^$", to avoid different error messages popup in the same time. FuYM $.validationEngineLanguage.allRules = { "required": { // Add your regex rules here, you can take telephone as an example "regex": "none", "alertText": "* 不能为空", "alertTextCheckboxMultiple": "* 请选择一个项目", "alertTextCheckboxe": "* 您必需勾选此栏位", "alertTextDateRange": "* 日期范不能为空" }, "dateRange": { "regex": "none", "alertText": "* 无效的 ", "alertText2": " 日期范围" }, "compareDate": { "regex": "none", "alertText": "* 起始日期大于截止日期 " }, "dateInRange": { "regex": "none", "alertText": "* 无效的日期范围", "alertText2": "* 无效的日期" }, "dateTimeRange": { "regex": "none", "alertText": "* 无效的 ", "alertText2": " 时间范围" }, "minSize": { "regex": "none", "alertText": "* 最少 ", "alertText2": " 个字符" }, "maxSize": { "regex": "none", "alertText": "* 最多 ", "alertText2": " 个字符" }, "groupRequired": { "regex": "none", "alertText": "* 您必需选填其中一个栏位" }, "min": { "regex": "none", "alertText": "* 最小值为 " }, "max": { "regex": "none", "alertText": "* 最大值为 " }, "past": { "regex": "none", "alertText": "* 日期必需早于 " }, "future": { "regex": "none", "alertText": "* 日期必需晚于 " }, "maxCheckbox": { "regex": "none", "alertText": "* 最多选取 ", "alertText2": " 个项目" }, "minCheckbox": { "regex": "none", "alertText": "* 请选取 ", "alertText2": " 个项目" }, "equals": { "regex": "none", "alertText": "* 栏位內容不相符" }, "phone": { // credit: jquery.h5validate.js / orefalo "regex": /^(\d{3,4}-)?\d{7,8}(-\d{1,})?$/, /** /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$|^$/,**/ "alertText": "* 无效的电话号码,格式应为:区号-固话号码-分机号" }, "phone1": { // credit: jquery.h5validate.js / orefalo 电话号中间可以有“-” 也可以没有 "regex": /^(\d{3,4}-*)?\d{7,8}(-*\d{1,})?$/, /** /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$|^$/,**/ "alertText": "* 无效的电话号码" }, "mobile": { "regex": /^\d{11,12}?$/, "alertText": "* 无效的手机号码,格式应为:11位或12位数字" }, "referer": { "regex": /^[@._a-zA-Z0-9\u4e00-\u9fa5]{0,30}$/, "alertText": "* 推荐人信息应为30位以内的汉字、数字、字母、@、点号以及下划线组成" }, "email": { // Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/email_address_validation/ "regex": /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$|^$/i, "alertText": "* email 地址不合法" }, "integer": { "regex": /^[\-\+]?\d+$/, "alertText": "* 不是有效的整數". }, "number": { // Number, including positive, negative, and floating decimal. credit: orefalo "regex": /^[\-\+]?(([0-9]+)([\.,]([0-9]+))?|([\.,]([0-9]+))?)$/, "alertText": "* 无效的數字" }, "date": { "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^$/, "alertText": "* 无效的日期,格式必需为 YYYY-MM-DD" }, "ipv4": { "regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/, "alertText": "* 无效的 IP 位址" }, "url": { "regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i, "alertText": "* 非法的 URL" }, "onlyNumberSp": { "regex": /^[0-9\ ]+$|^$/, "alertText": "* 只能填數字" }, "onlyLetterSp": { "regex": /^[a-zA-Z\ \']+$|^$/, "alertText": "* 只接受英文字母大小寫" }, "onlyLetterNumber": { "regex": /^[0-9a-zA-Z]+$|^$/, "alertText": "* 不接受特殊字元" }, // --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings "ajaxUserCall": { "url": "ajaxValidateFieldUser", // you may want to pass extra data on the ajax call "extraData": "name=eric", "alertText": "* 此名称已经被其他人使用", "alertTextLoad": "* 正在确认名称是否有其他人使用,请稍等。" }, "ajaxUserCallPhp": { "url": "phpajax/ajaxValidateFieldUser.php", // you may want to pass extra data on the ajax call "extraData": "name=eric", // if you provide an "alertTextOk", it will show as a green prompt when the field validates "alertTextOk": "* 此账号名称可以使用", "alertText": "* 此账号名称已经被其他人使用", "alertTextLoad": "* 正在确认账号名称是否有其他人使用,请稍等。" }, "ajaxNameCall": { // remote json service location "url": "ajaxValidateFieldName", // error "alertText": "* 此名称可以使用", // if you provide an "alertTextOk", it will show as a green prompt when the field validates "alertTextOk": "* 此名称已經被其他人使用", // speaks by itself "alertTextLoad": "* 正在确认名称是否有其他人使用,请稍等。" }, "ajaxNameCallPhp": { // remote json service location "url": "phpajax/ajaxValidateFieldName.php", // error "alertText": "* 此名称已经被其他人使用", // speaks by itself "alertTextLoad": "* 正在确认名称是否有其他人使用,请稍等。" }, "validate2fields": { "alertText": "* 请输入 HELLO" }, //tls warning:homegrown not fielded  "dateFormat":{ "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/, "alertText": "* 无效的日期格式" }, //tls warning:homegrown not fielded  "dateTimeFormat": { "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1})$/, "alertText": "* 无效的日期或时间格式", "alertText2": "可接受的格式: ", "alertText3": "mm/dd/yyyy hh:mm:ss AM|PM 或 ", "alertText4": "yyyy-mm-dd hh:mm:ss AM|PM" }, //Rules below here were defined by ourself, FuYM "lengthRange":{ "regex":"none", "alertText":"* 长度为 ", "alertText2":" 到 ", "alertText3": " 个字符" }, "codeLength":{ "regex":"none", "alertText":"* 长度必需", "alertText2": " 个字符" }, "cardNo":{ "regex":/(^[0-9\ ]+$)|^$/, "alertText":"* 账号只能输入数字" }, "onlyNumber":{ "regex":/(^[0-9]+$)|^$/, "alertText":"* 只能输入数字" }, "onlyLetter":{ "regex":/(^[a-zA-Z]+$)|^$/, "alertText":"* 只能输入字母" }, "numOrletter":{ "regex":/(^[a-zA-Z0-9]+$)|^$/, "alertText":"* 只能输入数字或字母" }, "numAndLetter":{ "regex":/(^(([a-zA-Z]+[0-9]+)|([0-9]+[a-zA-Z]+))[a-zA-Z0-9]*$)|^$/, "alertText":"* 必须为数字和字母的组合" }, "number2":{ "regex":/(^(([1-9]+[0-9]*(\.\d{1,2})?)|0|(0\.\d{1,2}))$)|^$/, "alertText":"* 只能输入数字,可带两位小数" }, "keyboard":{ "regex":"none", "alertText":"* 不能为空", "alertText2":"* 长度应为", "alertText3": " 个字符" }, "cardMonth":{ "regex":"none", "alertText1":"* 不能为空", "alertText2":"* 只能是2位数字", "alertText3":"* 月份输入不合法" }, "numOrLetterOrUnderline":{ "regex":/(^[a-zA-Z0-9\_]+$)|^$/, "alertText":"* 只能输入数字或字母或下划线" }, "numOrLetterOrDot":{ "regex":/(^[a-zA-Z0-9\.]+$)|^$/, "alertText":"* 只能输入数字或字母或点" }, //Same as "equals", used in last version "confirm":{ "regex":"none", "alertText":"* 两次输入不一致" }, "moneyCompare":{ "regex":"none", "alertText":"* 最小金额大于最大金额" }, "simplePwd":{ "regex":/^((?!\b000000\b|\b111111\b|\b222222\b|\b333333\b|\b444444\b|\b555555\b|\b666666\b|\b777777\b|\b888888\b|\b999999\b|\b012345\b|\b123456\b|\b234567\b|\b345678\b|\b456789\b|\b987654\b|\b876543\b|\b765432\b|\b654321\b|\b543210\b).)*$/, "alertText":"* 您的密码过于简单,请到柜面或ATM上修改后再操作;e卡客户可通过网银服务管理-密码修改功能下直接修改;信用卡客户可通过信用卡登录-密码管理功能下直接修改。" } }; } }; $.validationEngineLanguage.newLang(); })(jQuery);

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110295.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 为什么有的文件从SVN上更新不下来

    为什么有的文件从SVN上更新不下来

    2021年10月20日
  • java它 —— 图形界面(两)

    java它 —— 图形界面(两)

  • 学了一天java,我总结了这些知识点

    学了一天java,我总结了这些知识点大家好,我是KookNut39也是Tommy,在CSDN写文,写Java时候我是Tommy,分享一些自己认为在学习过程中比较重要的东西,致力于帮助初学者入门,希望可以帮助你进步。以前一直更新C/C++方面的知识,今天是我第一次更新Java方面的知识,以后会持续更新,感兴趣的欢迎关注博主,和博主一起从0学习Java知识。大家可以去专栏查看之前的文章,希望未来能和大家共同探讨技术。文章目录1.注释(1)单行注释(2)多行注释(3)文档注释2.关键字3.保留字4.标识符5.Java数据类型(1)基本数据类型.

  • Oracle创建用户、角色、授权、建表

    Oracle创建用户、角色、授权、建表oracle数据库的权限系统分为系统权限与对象权限。系统权限(databasesystemprivilege)可以让用户执行特定的命令集。例如,createtable权限允许用户创建表,grantanyprivilege权限允许用户授予任何系统权限。对象权限(databaseobjectprivilege)可以让用户能够对各个对象进行某些操作。例如delete权限允许用

  • Jmeter 之正则表达式提取器应用「建议收藏」

    Jmeter 之正则表达式提取器应用「建议收藏」目录前言一、获取单个数据二、获取多个数据个人觉得非常非常细节的地方注意一下:前言说到Jmeter正则表达式提取器的应用,就不得不说到关联。所谓关联,就是把应用中动态变化返回的数据获取到,把它保存为一个参数,提供给后面需要用到的地方进行使用。Jmeter中关联可以通过“添加—后置处理器—正则表达式提取器”来获取数据,且注意正则表达式提取器附在需要获取数据的某个采样器之下,数据一般从“查看结果树“的响应数据获取。Jmeter中关联可以通过“添加—后置处理器—正则表达式提.

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号