Solved

Syntax for a regular_expression validation

Posted on 2003-10-22
10
178 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 

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 50 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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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