How do I exclude alphabetic characters & numbers beginning with zero, using RegEx?
I have a class that initiate this function...but I need to modify it's regex.
I would like to exclude all alphabetic characters and any numbers beginning with 0[zero].
$(开发者_开发知识库'.numeric').keyup(function () {
$(this).toggleClass('field-error', /(0|00|000)$/.test(this.value));
});
Jquery Code:
$(document).ready( function(){
$('#test_regex').click( function(){
regex= /^[a-zA-Z0]+$/;
str= $('#reginput').val();
result= regex.test(str);
if( result ){
alert("Value contains alphabet or begin with zero number");
}else{
alert("It's the correct value");
}
});
});
HTML Code:
<input type="text" id="reginput"/>
<button id="test_regex">Check Value</button>
Maybe it's what you want...
I believe you are looking for a regex that can detect non digit characters and leading zeroes in the field. The regex below maybe of help
[^\d]+|^0
This regex when used with test function will return true if the string contains any non digit character or if it starts with digit zero. ^[a-zA-Z0]+$ will not match the string "123asd562"
精彩评论