...

View Full Version : check predetermine format.



CstAn
02-05-2007, 03:35 PM
Hi, i had some predetermine format of data need to check my javascript.

this the code i write:


reg = /\d{2}\:\d{2} H/;

if(!reg.test(hours1))
alert("wrong format."):


the format i want is "00:00 H" a space at left hand side of the value H.

but it can get what i want.

can anyone correct for me?

thanks

chump2877
02-05-2007, 04:42 PM
<script type="text/javascript">

reg = /\d{2}:\d{2} H/;

var hours1 = '34:86 H';
var hours2 = '4:86 H';
var hours3 = '34:6 H';
var hours4 = '34:86H';
var hours5 = '34:86';

if (!reg.test(hours1))
alert('"'+hours1+'" is the wrong format.');
else
alert('"'+hours1+'" is the correct format.');

if (!reg.test(hours2))
alert('"'+hours2+'" is the wrong format.');
else
alert('"'+hours2+'" is the correct format.');

if (!reg.test(hours3))
alert('"'+hours3+'" is the wrong format.');
else
alert('"'+hours3+'" is the correct format.');

if (!reg.test(hours4))
alert('"'+hours4+'" is the wrong format.');
else
alert('"'+hours4+'" is the correct format.');

if (!reg.test(hours5))
alert('"'+hours5+'" is the wrong format.');
else
alert('"'+hours5+'" is the correct format.');

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum