Forum Moderators: open
if(!aform.txtheight.value.match(/^\d*\.\d{1,1}$/)) {
OutMessage = "Incorrect Measurement, please enter with a period i.e 5.7\n";
FocusControl = aform.txtheight;
}
Thank you for your help and time.
First of all: Welcome to Webmaster World!
Here a regular expression that should do the trick:
/([1-9]+[\.]{1}[0-9]+¦[0]{1}[\.]?[0-9]*$)/
Either matches 1 to 9 followed by exactly one decimal point, followed by one or more 0-9 digits
OR
one 0 followed by zero or one decimal places, followed by zero or more 0-9 digits.
This accept responses like 2.4, 5.8, 0, 0.0, 0.124, etc. but will reject single digits like 2,4,5, etc.
Hope this helps,
ajkimoto
I have tried the string you suggested and I must be doing something wrong as now it accepts nothing, constantly displaying the alert message. I'm sure it's an easily fixed problem but as I am new at this, I again ask for your help. Here is the way I have the code now:
if(!aform.txtheight.value.match (/([1-9]+[\.]{1}[0-9]+¦[0]{1}[\.]?[0-9]*$)/ )) {
OutMessage = "Incorrect Measurement, please enter with a period i.e 5.7\n";
FocusControl = aform.txtheight;
}
Thank you,
Sangarius
I rechecked the RE, and it appears to be correct. One thing that I did notice is that the 'pipe' character, ascii 124, seems to be replaced by ascii 166 by the BBS software, which will give you the behavior that you describe.
Try to replace the ¦ in the RE statement with the shift-backslash key and see if that works.
ajkimoto