|
-
Jun 18th, 2002, 09:25 AM
#1
Thread Starter
Lively Member
Need help on White space
i am creating a web page that allows visitors to enter information in text boxes and i want to be able to perform a check to see if the information enetered into the text boxes is only numbers and no white spaces(blank spaces) but i have no idea on how to go around doing this! can someone help me out? im a newbie to all this! thanks!
-
Jun 19th, 2002, 02:52 AM
#2
Frenzied Member
Code:
<html>
<head>
<script language="JavaScript1.2"><!--
function regular(string) {
if (string.search(/^[0-9]*$/) != -1)
return true;
else
return false;
}
//--></script>
</head>
<body>
<form>
<input type="text" onChange="if (!regular(this.value)) alert('Not Valid')">
</form>
</body>
</html>
-
Jun 19th, 2002, 08:55 AM
#3
Thread Starter
Lively Member
-
Jun 19th, 2002, 10:04 AM
#4
Thread Starter
Lively Member
Re:help please
sorry to do this mark but i was wondering if i could return the focus to the textbox with the error in it!
-
Jun 19th, 2002, 10:15 AM
#5
Frenzied Member
Have you got several textboxes then?
Are you submitting the form somewhere?
-
Jun 19th, 2002, 10:29 AM
#6
Frenzied Member
this might help:
Code:
<html>
<head>
<script language="JavaScript1.2"><!--
function regular(string) {
if (string.search(/^[0-9]*$/) != -1)
return true;
else
return false;
}
function verify()
{
var j;
for(j=0;j<document.frm1.txt1.length;j++)
{
if(!regular(document.frm1.txt1[j].value))
{
alert('Not Valid');
document.frm1.txt1[j].focus();
return false
}
}
return true;
}
//--></script>
</head>
<body>
<form onSubmit='return verify()' name='frm1'>
<input type="text" name="txt1"><br>
<input type="text" name="txt1"><br>
<input type="text" name="txt1"><br>
<input type="text" name="txt1"><br>
</form>
</body>
</html>
-
Jun 19th, 2002, 11:42 AM
#7
Thread Starter
Lively Member
oh sorry for the late reply mark! i want to check all the textboxes after they lose the focus! can i just insert the script you just posted in the tags by using onBlur? thanks
-
Jun 20th, 2002, 02:40 AM
#8
Frenzied Member
Try this:
Code:
<html>
<head>
<script language="JavaScript1.2"><!--
function regular(string) {
if (string.search(/^[0-9]*$/) != -1)
return true;
else
return false;
}
function verify(t)
{
if(!regular(t.value))
{
alert('Not Valid');
t.focus();
return false
}
return true;
}
//--></script>
</head>
<body>
<form>
<input type="text" onBlur="verify(this)"><br>
<input type="text" onBlur="verify(this)"><br>
<input type="text" onBlur="verify(this)"><br>
<input type="text" onBlur="verify(this)"><br>
</form>
</body>
</html>
-
Jun 20th, 2002, 09:55 AM
#9
Thread Starter
Lively Member
it all works great mark but just 2 little flaws that i have just found: if i leave the textbox so that the value has absolutely no contents(length=0), it will not work!; and i want to be able to get rid of leading zeros, if possible. im sorry i didnt tell you this earlier but i just saw it now! sorry to be a pain! thanks for everything
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|