Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Syntax for a regular_expression validation

Posted on 2003-10-22
10
Medium Priority
?
180 Views
Last Modified: 2013-12-24
I need to validate a text field with a regular_expression.  I want to ensure that a user enters a time in the format HH:MM AM or HH:MM PM.

I thought I had the syntax correct...but it is not working correctly.

<cfinput type="text" validate="regular_expression" pattern="[0-9]{1,2}\:[0-9]{2}\s[AM|PM]" name="starttime" required="yes" message="Please enter a valid start time in the format HH:MM AM or HH:MM PM.">

Any suggestions?
0
Comment
Question by:SherryG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 16

Expert Comment

by:_nn_
ID: 9600013
Wild guesses (I don't know CF, but I know regexps)

- ":" doesn't need to be escaped
- "(|)" instead of "[|]"

pattern="[0-9]{1,2}:[0-9]{2}\s(AM|PM|am|pm)"

Possibly, you'd like to prevent anything else in the expression

pattern="^[0-9]{1,2}:[0-9]{2}\s(AM|PM|am|pm)$"

HTH
0
 

Author Comment

by:SherryG
ID: 9600819
That partially works.

If I enter 1:00 I get the error indicating that I need to use the correct format, in which case I change it to 1:00 PM and it works fine.

If I enter 11:00 it goes directly into the DB without an error.  I need the user to be prompted to enter the AM or PM if they forget.  For some reason, the code is not catching that error.

Any suggestions.
0
 

Author Comment

by:SherryG
ID: 9600820
That partially works.

If I enter 1:00 I get the error indicating that I need to use the correct format, in which case I change it to 1:00 PM and it works fine.

If I enter 11:00 it goes directly into the DB without an error.  I need the user to be prompted to enter the AM or PM if they forget.  For some reason, the code is not catching that error.

Any suggestions.
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:SherryG
ID: 9600821
That partially works.

If I enter 1:00 I get the error indicating that I need to use the correct format, in which case I change it to 1:00 PM and it works fine.

If I enter 11:00 it goes directly into the DB without an error.  I need the user to be prompted to enter the AM or PM if they forget.  For some reason, the code is not catching that error.

Any suggestions.
0
 
LVL 2

Expert Comment

by:jonnygo55
ID: 9601728
ignore this if it not an option but why dont you create a little dropdown with AM and PM and add the 12 hours accordingly on the server side...
0
 
LVL 16

Accepted Solution

by:
_nn_ earned 200 total points
ID: 9605555
Hmm, strange. I've just finished testing following one in javascript and it works ok for my IE6 :

pattern="^\d{1,2}:\d\d\s(AM|PM|am|pm)$"

HTH
0
 

Author Comment

by:SherryG
ID: 9606823
Thanks HTH.  There was a problem on my page.  Once I resolved it your code worked perfectly.
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9606900
Thanks and glad I could help a it.

PS: For future reference, HTH is not my name, it's an acronym and stands for "Hope This Helps" or "Hope That Helps" :)
0
 

Author Comment

by:SherryG
ID: 9606911
Sorry about that...I just assumed they were your initials!
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9606936
>> Sorry about that...I just assumed they were your initials!

Your assumption was perfectly normal and I should be the one apologizing for being a lazy typer :)
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
What You Need to Know when Searching for a Webhost Provider
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question