Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to check input

Status
Not open for further replies.

liteon

Programmer
Jan 7, 2003
11
0
0
DE
Can someone help me writing a script that will check if text field contain name and family name and verify that there is space (at least 1 empty space) between the names.

Html:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
Input Name and Family name:
<input name=&quot;input&quot; type=&quot;text&quot; id=&quot;input&quot;>
</body>
</html>
 
When you same name and family name, is there a specific list of acceptable names? Or will any characters be acceptable? Is there a minimum number of characters for each set? Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
OK, good question. The page POST to a PHP script after it and I do not want characters like /[~`!Ҥ@#$%^&*()_+=:;'{}\. And how do I check that there are only two words separated by space or couples of space.

 

<script>
function alphaOnly(inString){
var illChar = /[~`!@#$%^&*()_+=0123456789:;&quot;'{}\[\]]/gi;

if (inString.search(illChar) != -1){
return false;
}
return true;
}

function twoNames(inField){
nameArr = inField.value.split(/\S+/) //split on one or more spaces
if(nameArr.length != 1){
boolGood = false
}
else{
boolGood = alphaOnly(inField.value)
}
if (!boolGood){
alert (&quot;Please enter a valid name!&quot;)
inField.focus()
}
}
</script>
<input onBlur=&quot;twoNames(this)&quot;> Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top