开发者

How to write Regex For this form plugin

开发者 https://www.devze.com 2023-01-26 23:28 出处:网络
iam using this form Plugin which can also Accept regex for validation http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

iam using this form Plugin which can also Accept regex for validation http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ Iam looking for Regex Validation where the User can enter the value between 1 and 250 . it cannot accept "0" also .The following should not be allowed no speacial chara开发者_运维知识库cters and as well as no negative number such as -1 -2 -3 and so on this is the form which it can accept "/^[1-9][0-9]?$/"


^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|250)$


checking if a value is in a given range is not a typical scenario for the use of regular expressions. You could do that, but the plugin also seems to support custom validation functions which i would prefer in this case, because they are easier to read and understand. A custom function for your validation task would look like this:

function validate(){
  var value = parseInt($("#fieldId").val());
  return value > 0 && value <= 250
}
0

精彩评论

暂无评论...
验证码 换一张
取 消