Feeds:
Posts
Comments

Archive for April, 2008

I was working with struts validators and need to test a phone number to be digits and starts with a leading 00, I wanna share it here

^00+\d{9,17}$

below is a ruby code snippet:

phone_no=”009621111111″

if phone_no =~ /^00+\d{0,9}$/

puts “match”

else

puts “No match”

end

a quick explain is

^ start from the beginning of the string

+\d{9,17} should include digits with at least 9 digits and at most 17 digits (excluded the leading 00)

$ indicates the end of the string

well, that was not much, but I wish it save someone’s 10 minutes!

Cheers

Advertisements

Read Full Post »