Reputation: 10885
Hi i want to validate a string with in which only numbers are allowed and only one # sign at
the end.I use this but it allow double # sign at end.
/^[0-9]+#/
How i can refine it to only allow single # sign at end of string like 1345#
Upvotes: 1
Views: 1823
Reputation: 15771
Don't use ^
and $
. Use \A
and \z
instead! It's a big gotcha!
/\A[0-9]+#\z/
^
and $
are used to specify the end of the LINE, not sting!
# don't do this!!!
/^[0-9]+\#$/ =~ "12#\nfoo" # MATCHES!!!
I hope it'll help someone else!
Upvotes: 5