Help Needed

R

Ramu Ravi

Dear All,


I am facing another problem. I am trying to validate hours. In my case, i
want the hours to be represented in 12hour format. What i mean is the
single digit hours should be preceeded with 0.(01,02,03...).

I am using the following expression in a function to validate for
numbers(hours).

function testnumber()
{
var src = event.srcElement;

var num=parseInt(TxtValue); ' TxtValue has the value of hours.

if (!(/^\d{2}$/.test(num))) {

alert (' Invalid Time')

return false

}


it gives me an error for all hours, i.e., number apart from 10,11,12.

I am explicitly adding 0 to represent the single digit hours in the textbox.
My function is not recognising the value even after converting to integer
using parseInt.

Or is there any other way to validate the hour and preceeded with 0 provided
if the hour is in single digit.


TIA
Ravi
(e-mail address removed)
 
P

Per Hornshøj-Schierbeck

Hey Ravi

This is kind of a wierd place to post a javascript problem? ;) Anyways as
far as i can see - your problem lies in you're trying to validate the parsed
integer not the string digit. The parsed integer will always be a single
digit when it's not 10, 11 og 12. So your pattern won't match it.

You could change it to validate against TxtValue instead of num ;)

Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top