Solved

Syntax for a regular_expression validation

Posted on 2003-10-22
10
176 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
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apached AXIS end to end simple good example 2 98
Using random iterations in password hashing.  Good or Bad? 4 88
Web Site Hosting 10 89
spamming  on Hosted svrs? 6 98
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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