I need a regular expression for a text field in my asp.net website
which should lie in between
0000 to 9999
it is not be
0 to 9999
I need a regular expression for a text field in my asp.net website
which should lie in between
0000 to 9999
it is not be
0 to 9999
I think this could be:
^\d{4}$
Don't forget to escape it if you are using c#
string numReg = @"^\d{4}$";
Along with the other answers, you could also try this.
^[0-9]{4}$
Use a gigantic switch statement!
switch(val){
case "0000":
print "0000";
break;
// ...
case "9999":
print "I'm sick of typing";
break;
}
Using a little logic. (Humorous, similar to "gigantic switch")
Ruby
def validate num
return false unless num.length == 4
return false unless num.to_i.between?(-1, 10000)
num.each_char {|ch| return false unless '0123456789'.include? ch }
true
end
puts validate '404' #false
puts validate '9321' # true
puts validate '-302' #false
puts validate 'AAAA' # false