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);

 

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Windows10系统设置定时关机「建议收藏」

    Windows10系统设置定时关机「建议收藏」1.输入cmd运行命令提示符2.输入 shutdown–s–t3600   [注:3600为倒计时的秒数,此语句为系统在一小时后关机]/*shutdown命令的参数:shutdown-a 取消关机shutdown-s关机shutdown-f 强行关闭应用程序shutdown-m计算机名 控制远程计算机shutdown-i 显示“远程关机”图形用户界面,…

    2022年5月15日
    43
  • 入门级Unity安装教程

    入门级Unity安装教程这是一篇面向对unity感兴趣,想要学习unity,但是还处于入门阶段的小伙伴的超详细unity安装教程。因为是面向入门的小伙伴,所以文章写的有点长,还配有许多图片,这样才能更详细的介绍安装流程。但是不必担心太长看起来太费劲,各位只要照着教程一步步来就可以了。跟着这章博文走,最终你的电脑一定能张开双臂,成功拥抱unity。那么,现在进入正题吧!1.进入官网unity的官网链接:unity.cn…

    2022年6月27日
    30
  • vim 设置搜索高亮_vim取消搜索后高亮持续

    vim 设置搜索高亮_vim取消搜索后高亮持续vim搜索设置高亮linuxvim打开文档搜索字符串时,设置被搜索到字符串高亮显示。有两种方法:1、临时设置:vim打开文档–>命令行形式输入sethlsearch。缺点:关闭文档后,下次打开,又需要重新设置一遍。2、永久设置(推荐):在~/.vimrc中配制vim~/.vimrc在文件中加上sethlsearch 然后保存退出便可。

    2022年9月24日
    3
  • vue ajax获取数据的时候,如何保证传递参数的安全或者说如何保护api的安全

    vue ajax获取数据的时候,如何保证传递参数的安全或者说如何保护api的安全

    2021年10月13日
    36
  • 蓝屏代码0x000000be_电脑蓝屏0*000000ed怎么解决

    蓝屏代码0x000000be_电脑蓝屏0*000000ed怎么解决windows系统相信大家最怕的就是遇到蓝屏的问题了,不太好解决,这不有朋友反馈电脑出现蓝屏代码0x000000BE的问题,电脑此时已经不能用了,那么要怎么解决呢?如果不知道如何操作的话,不妨先试试小编教大家的方法。蓝屏代码0x000000BE是什么意思?0x000000BE错误表示硬件设备的驱动程序试图向只读内存错误地写入数据,这个错误一般是因为硬件设备驱动程序存在BUG或安装不正确引起的。解决…

    2022年10月8日
    2
  • 【原创】让你的系统轻松预览AI,PSD,EPS,CDR缩略图!

    【原创】让你的系统轻松预览AI,PSD,EPS,CDR缩略图!不知道怎么回事,我机子上的IllustratorCS3搞上之后还是无法预览AI和EPS的缩略图,有时候需要选用素材的时候,面对着很多的文件无法预览,只能一个一个猜着看,今天终于无法忍受了.于是上网查了一下.原来搞定很简单,只需要把那些大软件的一些DLL文件搞进系统就行了.下边是整理的一些补丁,不用安装,只需要拷贝到特定目录然后再倒入注册表文件就行了.文件包里有具体的使用方法.文件:…

    2022年4月30日
    66

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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