By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

[JavaScript] Problem with Regular Expression

100+
P: 263
[Javascript] Problem with Regular Expression

Hi all,

First of all I must say that I am a newbie when it comes to javascript language.
Here is my problem.

I need validate in `myForm` this string:
Expand|Select|Wrap|Line Numbers
  1. 09 - AB800
And try this Regular Expression:
Expand|Select|Wrap|Line Numbers
  1. if (!myForm.Folder.value.match("/^0[0-9] \- [a-z0-9]{5,20}$/i", "")) {
  2.      window.alert('Not valid.');
  3.      myForm.Folder.focus();
  4.      myForm.Folder.select();
  5.      return false;
  6.      }
  7.  
But the correct string:
Expand|Select|Wrap|Line Numbers
  1. 09 - AB800
is not validate. Why?

I need also optional add this other string:
Expand|Select|Wrap|Line Numbers
  1. 09 - AB800/test
when the string part `/test` is not required.

Can you explain any one or any sample code related this...

Your help would be very appreciated.
thanks for your time and hints.

Thanks in advance.
Cheers
May 25 '12 #1

✓ answered by Dormilich

the main problem is that .match() expects a RegExp object to be given, not two strings.

Share this Question
Share on Google+
4 Replies


Dormilich
Expert Mod 5K+
P: 8,639
the main problem is that .match() expects a RegExp object to be given, not two strings.
May 25 '12 #2

100+
P: 263
Hello.
I'd appreciate your help so very much.

What is your suggestion?
May 25 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
pass a RegExp object.
May 25 '12 #4

100+
P: 263
Thanks you very much for your help
I'm really happy for your quickly answer.
Good bye
May 25 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.