...

View Full Version : Regular Expression



tqmd1
01-20-2012, 06:15 PM
Dear experts

I have following codes

Var re=/(\d){4}-(\d){7}/;

When I test this string
0300-685706263

It says TRUE

But I validate this string exactly

0300-6857062

Please help

Amphiluke
01-20-2012, 06:30 PM
Not sure that understand you correctly. Maybe this will help:

var re=/^(\d){4}\-(\d){7}$/;

Philip M
01-20-2012, 06:48 PM
Dear experts

I have following codes

Var re=/(\d){4}-(\d){7}/;

When I test this string
0300-685706263

It says TRUE

But I validate this string exactly

0300-6857062

Please help

0300-685706263 returns true because it matches your pattern. What you want is to match your pattern and nothing but. As amphiluke has shown you.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum