Validating charater strings using javascript

6854933580_2c8b688306_z

So here is the Regular expression pattern:/^[A-Z][0-9] ?[0-9][A-Z]$/i The i at the end of the pattern is to indicate that this is a case insensitive match.By placing Regular expressions are quite powerful and if you can master them, they will save you a ton of coding time.Instead of parsing through the string using tokens or some other nonsense we managed to validate our string using a single line of code.

Now let’s jump to the regular expression itself: UK postal code examples : EC1A 1BB W1A 0AX M1 1AE B33 8TH CR2 6XH DN55 1PT So, 1 or 2 alphabetic characters, followed by 1 or 2 digits, then a space and one digit and exactly two alphabetic characters.

It has an onsubmit event attached to a function called validate() that we are going to create later inside this form there are three inputs one for our phone number another one is for postal codes and the third and the last one is a submit button that is going to submit the form after we are done filling it. It contains only the code that validates the phone number.

In the first line, I am using Element By Id() to grab the phone number from the input element.

We’ll say that a red rectangle holds a weak password, orange medium, and green a strong password.

The HTML behind this would look something like the following: Moving beyond the basic Angular JS stuff, lets get down to the good stuff.

In this tutorial you will see how to use regular expressions to validate.

You must have an account to comment. Please register or login here!