String pattern matching in Javascript

Posted by kwokwai on Stack Overflow See other posts from Stack Overflow or by kwokwai
Published on 2010-06-10T13:06:20Z Indexed on 2010/06/10 13:12 UTC
Read the original article Hit count: 231

Filed under:
|

Hi all,

I am doing some self learning about Patern Matching in Javascript.
I got a simple input text field in a HTML web page,
and I have done some Javascript to capture the string and check if there
are any strange characters other than numbers and characters in the string.
But I am not sure if it is correct.
Only numbers, characters or a mixture of numbers and characters are allowed.

var pattern = /^[a-z]+|[A-Z]+|[0-9]+$/;

And I have another question about Pattern Matching in Javascript,
what does the percentage symbol mean in Pattern matching. For example:

var pattern = '/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/';

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex