Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression for (1,0),(2,0),(3,0)

Status
Not open for further replies.

hemajb

Programmer
Sep 26, 2003
19
IN
Could anyone tell me what would be the regular expression
(1,0),(2,0),(3,0) ?? This is quiet urgent
 
Can you explain how you are using the regular expression?

Are you just checking the pattern?

Are you checking those specific values?

And new RegExp() can be used if this is a variable
value.


2b||!2b
 
Am using it this way
function checkSyntax()
{
var value = '(1,0),(2,1),(3,1),(4,0)';
regex= /^(\(\d{1,3},[0-1]\)(,{0,1}))+$/;
var nArray = value.match(regex);
if (nArray==null)
alert("not a proper pattern");
else
alert("Proper pattern");
}

value can take (1,0),(2,1),(3,0)....
The problem with this code is it works fine even when i give (1,0),(2,0),
the pattern must not end with a comma..
 
Try,

regex= /^(\(\d{1,3},[0-1]\),{1})+(\(\d{1,3},[0-1]\))$/;

worked in my tests

2b||!2b
 
My sincere thanks for the help.You solved my problem.
Cheers
 
So dumb of me , i didnt check this for just (1,0). it doesnt work when there is just one sequence
 
By using * we can tell it 0 or more where the
+ looks for one or more.

Try this:

re = /^(\(\d{1,3},[0-1]\),{1})*(\(\d{1,3},[0-1]\))$/;

2b||!2b
 
Thanks, It works fine now
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top