I'm a moderately advanced beginner with regex, and I've come up with this one I'm pretty sure will work, but I'd appreciate a proofreading before going live with it:
^[0-9, ]+$
It should match if the value is all numbers and/or spaces, but is it effecient as it could be?
Should I include dashes too?
And what if the value has no numbers? (I guess I could check first for all spaces & dashes and handle that case differently. No sense in telling the customer they've entered a CC# where it shouldn't be if they've not entered any digits.)
Thanks!
2006-09-19
08:16:11
·
2 answers
·
asked by
John's Secret Identity™
6
in
Computers & Internet
➔ Programming & Design
Note that I'm not trying to validate a card #. I'm just trying to detect when the customer *tries* to type in a card # in the wrong place, even if they misstype the number.
Also note that Amex #s aren't given in 4x4 format. And our site will accept #s entered with or without spaces and/or dashes anyway, so the expression aught to detect anything that it would accept.
2006-09-23
13:01:02 ·
update #1