1

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}/';

askedJun 10, 2010 at 13:06
user327712's user avatar
1
  • "Pattern Matching" is a called Regular Expressions or Regex. The Regex tag should help you connect with the right people.CommentedJun 10, 2010 at 13:08

2 Answers2

3

You can put multiple character ranges inside a[] class.

var pattern = /^[a-zA-Z0-9]+$///or var pattern = /^[a-z0-9]+$/i // <- using "case insensitive" modifier

Percentage symbol means percentage symbol will be matched, it has no special meaning inside a regular expression.

answeredJun 10, 2010 at 13:09
Andy E's user avatar
Sign up to request clarification or add additional context in comments.

Comments

0

% in that JavaScript regex doesn't have any special meaning 0 - it's just one more matching character.

answeredJun 10, 2010 at 13:10
DVK's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.