I have this light regular expression to validate the coordinates: ^([0-9.,-]+){18,20}$^. If the coordinates for example is 33.431441,-170.15625 and are under 18 characters, I’ll get an error message. Good! But if I add more characters to say 23 or more it will pass even if I have set an lock to 20.
You can test the regexp on http://regexpal.com/.
How can I fix this problem?
Thanks in advance.
You need the leading carat, or you are only checking the last 18-20 characters in the string:
Edit: also, drop the plus sign, as others have noted.
Edit2: Parens are superfluous
Edit3: need to escape the period (otherwise, it matches any character)