Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 用于文本字段验证的正则表达式_Ruby On Rails_Regex_Ruby On Rails 3_Validation_Jquery Validation Engine - Fatal编程技术网

Ruby on rails 用于文本字段验证的正则表达式

Ruby on rails 用于文本字段验证的正则表达式,ruby-on-rails,regex,ruby-on-rails-3,validation,jquery-validation-engine,Ruby On Rails,Regex,Ruby On Rails 3,Validation,Jquery Validation Engine,我正在使用JqueryValidationEngine在客户端验证表单 我想在表单中使用正则表达式验证文本字段。条件如下 编辑: It should not allow the user to enter single or multiple combinations of zeroes. E.g. '0', '00,, '00000' etc. It should not allow the user to enter the any multiple digit number start

我正在使用JqueryValidationEngine在客户端验证表单

我想在表单中使用正则表达式验证文本字段。条件如下

编辑:

It should not allow the user to enter single or multiple combinations of zeroes.

E.g. '0', '00,, '00000' etc.
It should not allow the user to enter the any multiple digit number starting with 0, but excluding the condition1. 

E.g. '01', '001, '001001' , '000001' etc.
条件1:

It should not allow the user to enter single or multiple combinations of zeroes.

E.g. '0', '00,, '00000' etc.
It should not allow the user to enter the any multiple digit number starting with 0, but excluding the condition1. 

E.g. '01', '001, '001001' , '000001' etc.
条件2:

It should not allow the user to enter single or multiple combinations of zeroes.

E.g. '0', '00,, '00000' etc.
It should not allow the user to enter the any multiple digit number starting with 0, but excluding the condition1. 

E.g. '01', '001, '001001' , '000001' etc.
我使用的是检查正则表达式,我需要两个正则表达式,用于不允许上述两种类型的值。谢谢:-

条件1:

^\d*[1-9]\d*$
条件2:

^[1-9]\d*$
条件1(根据OP的建议更新)

条件2(仅前0位的数字和至少一个非零的数字)

上面的倒数

/^((?!^0+[1-9][0-9]*$).)*$/

编写regex是为了避免出现这种模式。我希望以上是为了让他们通过我不知道你的评论是什么意思。如果出现您的条件,表达式将匹配。虽然您只需要二进制数,但修复了条件2。我猜最新的编辑是您想要的。我的解决方案是否有问题?实际上,使用Jqueryvalidationengine,即我们指定要验证的正则表达式,例如/^0+[1-9][0-9]*$/,这将允许值“001”,在字段中输入“0010”等。我希望用户在输入此正则表达式时不允许这样做,如果条件匹配,则返回一个错误。类似于
的Sthing如果输入=~regex则无效
只需检查rubular.com中的exp。我不能用If-else条件检查它。只是我可以指定一个正则表达式,该条目将被验证,并允许与正则表达式匹配的值。因此,我不希望输入问题中提到的值有任何建议?更新,但我不确定非数字,因为反向表达式会匹配这些值。如果您仍在寻找答案,则需要更新问题,因为可能不清楚您需要什么样的条件。如果有人想结束这个问题,请发表评论,以便我能够理解问题所在。