Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 15th, 2006, 08:46 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old September 15th, 2006, 08:51 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #3 (permalink)  
Old September 15th, 2006, 08:52 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #4 (permalink)  
Old September 15th, 2006, 09:11 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:06 AM.


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