JavaScript Tips n Tricks: Has only digits

Sometimes it’s necessary to do validation manually in javascript.  One that I had to do recently was to do a simple check that a value only had digits in it.  It should be obvious but since I had to look it up I figure I will post it so I can reference it in the future.


var notes = $("#txtContactExt").val();
if (/\D/.test(notes))
{
validationText += "*Please use numbers only for Phone Extension.";
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s