Enjoy an ad free experience by logging in. Not a member yet?
Register .
04-26-2004, 07:23 AM
PM User |
#1
New to the CF scene
Join Date: Apr 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
validate fields for numeric values only
Hello guys,
How can I validate that users have entered text or anything else for that matter and give them a pop up message informing they can only enter numbers.
I am new to this as you can see by my question,I hope somebody can help.
Regards
04-26-2004, 07:46 AM
PM User |
#2
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Here is an example:-
<tr>
<td><font face="Arial"><em><b>Club Membership No. (if applicable)</b></em></font></td>
<td><input type="text" size="8" maxlength="8" name="MemNumber" onblur="if(/\D/g.test(this.value)){alert('Only current Club membership numbers are valid in this box. ');this.value='';this.focus()}; </font></td></tr>
04-26-2004, 08:02 AM
PM User |
#3
New Coder
Join Date: Aug 2003
Location: Singapore
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Here's a script that works the same as Philip's.
Code:
var f = document.forms[0]
var v = f.NumField.value
for (i=0; i<v.length; i++)
{
if ((v.charCodeAt(i)<48 || v.charCodeAt(i)>57) && v.charCodeAt(i) !== 44 )
{
alert ( "This must be numeric." )
f.NumField.value = "";
f.NumField.focus()
return false
}
}
04-26-2004, 10:33 AM
PM User |
#4
Regular Coder
Join Date: Jul 2002
Posts: 698
Thanks: 0
Thanked 0 Times in 0 Posts
if(parseFloat(Field.value,10)==Field.value){}
or
if(parseInt(Field.value,10)==Field.value){}
04-26-2004, 10:40 AM
PM User |
#5
The thread killer
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
parseFloat doesn't need that second argument of 10 since it may only take decimal numbers, but the parseInt needs it.
Last edited by liorean; 04-26-2004 at 10:43 AM ..
04-26-2004, 10:43 AM
PM User |
#6
Supreme Master coder!
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
parseFloat() has no radix parameter unlike parseInt(). It always parse numbers in base 10
04-26-2004, 10:43 AM
PM User |
#7
The thread killer
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
Quote:
Originally Posted by glenngv
parseFloat() has no radix parameter unlike parseInt(). It always parse numbers in base 10
Beat you to it
04-26-2004, 11:00 AM
PM User |
#8
Supreme Master coder!
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 09:26 AM .
Advertisement
Log in to turn off these ads.