|
-
Mar 3rd, 2004, 08:46 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Javascript/RegEx : \d{2,4}
I'm using this code to validate a date
Code:
if ( testStr.match(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/) == null )
{
sMessage += 'Date is not in format DD/MM/YYYY';
document.getElementById('startdate').focus();
}
Now, I have a limited understanding of Regular Expressions but doesn't \d{2,4} mean that it matches either 2 or 4 numeric characters? Because it seems to be accepting 3 numeric characters too.
Last edited by TomGibbons; Mar 3rd, 2004 at 12:05 PM.
-
Mar 3rd, 2004, 09:11 AM
#2
You're right, but I'm not sure why it's not working. So as a last resort, use
d{4} instead of d{2,4}
-
Mar 3rd, 2004, 09:25 AM
#3
Thread Starter
Frenzied Member
Okay. Thanks anyway It could just be a FireFox issue.
-
Mar 3rd, 2004, 09:56 AM
#4
Addicted Member
\d{2,4} means atleast 2 digits, no more than 4. You could try \d{2}|\d{4}. That should give you what you want. You may need to wrap it in a parenthesis.
Travis, Kung Foo Journeyman
Web Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.5 Guide and Reference
Perl: Documentation, Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
OSS: Mozilla, MySQL (Manual)
-
Mar 3rd, 2004, 12:05 PM
#5
Thread Starter
Frenzied Member
Ahhh I see. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|