[ad_1]
Comprehensive unencrypted answer for newbies et al.
This is for all of the dummies like me who test the scripts written by some of you guys which do not work.
The following 3 examples are the steps I took to remove special characters AND extra spaces on the following 3 websites (all of which work perfectly) {1. EtaVisa.com 2. EtaStatus.com 3. Tikun.com} so I know that these work perfectly.
We have chained these together with over 50 at a time and NO problems.
// This removed special characters + 0-9 and allows for just letters (upper and LOWER case)
function NoDoublesPls1()
{
var str=document.getElementById("NoDoubles1");
var regex=/[^a-z]/gi;
str.value=str.value.replace(regex ,"");
}
// This removed special characters and allows for just letters (upper and LOWER case) and 0-9 AND spaces
function NoDoublesPls2()
{
var str=document.getElementById("NoDoubles2");
var regex=/[^a-z 0-9]/gi;
str.value=str.value.replace(regex ,"");
}
// This removed special characters and allows for just letters (upper and LOWER case) and 0-9 AND spaces
// The .replace(/\s\s+/g, ” “) at the end removes excessive spaces
// when I used single quotes, it did not work.
function NoDoublesPls3()
{ var str=document.getElementById("NoDoubles3");
var regex=/[^a-z 0-9]/gi;
str.value=str.value.replace(regex ,"") .replace(/\s\s+/g, " ");
}
::NEXT::
Save #3 as a .js
// I called mine NoDoubles.js
::NEXT::
Include your JS into your page
<script language="JavaScript" src="https://stackoverflow.com/questions/1981349/js/NoDoubles.js"></script>
Include this in your form field:: such as
<INPUT type="text" name="Name"
onKeyUp="NoDoublesPls3()" onKeyDown="NoDoublesPls3()" id="NoDoubles3"/>
So that it looks like this
<INPUT type="text" name="Name" onKeyUp="NoDoublesPls3()" onKeyDown="NoDoublesPls3()" id="NoDoubles3"/>
This will remove special characters, allow for single spaces and remove extra spaces.
[ad_2]