I would like to create a javascript regex to test a string that would accept only characters from 0 to 9, a to z, A to Z and the followings chars: + * . for a total length betwe
If you don't "anchor" the regular expression to indicate that matches should start at the beginning and end at the end of the test string, then that is taken to mean that you want to see if the pattern can be found anywhere in the string.
var reg = /^[0-9A-Za-z\+\*\.]{1,12}$/;
With ^
at the beginning and $
at the end, you indicate that the entire string must match the pattern; that is, that no characters appear in the string other than those that contribute to the match.
You're not setting it to match the start and end:
var reg = /^[0-9A-Za-z\+\*\.]{1,10}$/;