Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2006, 08:46 AM
Authorized User
 
Join Date: Sep 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript Pattern How To

I have construct a pattern to compare a string. But it is a bit long and I wonder is it a way to simplify my statement below:

Code:
// var format = 'xx/dd/yyyy'; // This will get alert 'False'
var format = 'mm/dd/yyyy'; // This will get alert 'True'

if (regExp.compile('dd', 'i').test(format) || 
    regExp.compile('mm', 'i').test(format) || 
    regExp.compile('yyyy', 'i').test(format)) {

    alert('>>>>>>>>>>> True');
} else {
    alert('>>>>>>>>>>> False');
}

Thank you for any advice.
 
Old September 15th, 2006, 08:51 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Do you mean it must contain the three strings "mm", "dd" and "yyyy" in any order and with anything else, e.g. "ddddddddddmmmmmmmmmmmmmyyyyyyyyyyyyyyy"?

--

Joe (Microsoft MVP - XML)
 
Old September 15th, 2006, 08:52 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Do you mean it must contain the three strings "mm", "dd" and "yyyy" in any order and with anything else, e.g. "dd123mmy456yyyy!£$%"?

--

Joe (Microsoft MVP - XML)
 
Old September 15th, 2006, 09:11 AM
Authorized User
 
Join Date: Sep 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, the string must contain pattern 'dd', 'mm' and 'yyyy' in any order, for instance, 'dd/mm/yyyy'or 'mm/dd/yyyy or 'yyyy-mm-dd', which means value 'ddddddddddmmmmmmmmmmmmmyyyyyyyyyyyyyyy' should throw false.

I think my statement will give 'True' by using value 'ddddddddddmmmmmmmmmmmmmyyyyyyyyyyyyyyy', which is not correct. It would be great, if your or anyone, could help to corect my logic.

Actually I have another problem which I don't know how to solve it by using pattern. It will be easier for us to understand by using a pseudocode expression:

Code:
var format = 'dd/mm/yyyy';

// pseudocode
if (format contains 2 '/' charaters)
   return true;
else // case if contains more/less than 2 or contains no '/' character
   return false;

Thanks in advance.






Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help with pattern recognition jazokita Pro Java 2 February 8th, 2009 05:34 PM
Ajax Pattern TheGame Ajax 1 July 26th, 2008 03:02 PM
Desing Pattern tilakkalyan J2EE 3 February 14th, 2006 07:04 AM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 19th, 2004 11:59 PM
javascript pattern matching... rbd Javascript 1 October 7th, 2004 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.