I’m creating simple form validation that excludes any entries that have a letter in them (basically anything from a-z or A-Z).
This is what I am currently using but my script only rejects anything that isn’t 0-9. which will reject periods, brackets and dashes which I want to validate.
var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
if(number != "" && !numericReg.test(number)) {
return false;
How can I check for letters only?
Another way to do this would be to only accept inputs that have numbers 0-9, and the following characters: “.”, “-“, “(“, “)”
Two regular expressions for you to try. The first matches strings that only contain the characters you specified. The second matches strings that contain no letters a-z or A-Z:
Keep in mind,
isNonAlphawon’t protect against ñüṃȅɍǒǘṩ ȯẗḥḛṝ ḽëʈťĕřś‼You may consider also allowing
xfor phone ex̲tensions and+for international dialing.