MichaelEvangelista
asked on
regEx to allow A-Z and single spaces only?
I am using a simple "onkeyup" with a regEx to replace anything but letters as the user types into a small text input. Works great... but I need to modify it so that *single* spaces are allowed.
Currently the code looks like this
<input type="text" size="12" maxlength="12" name="pfWord" id="pfWord"
onkeyup="this.value=this.v alue.repla ce(/[^a-z] /ig, '')">
How should I alter the regEx to also say
"allow spaces AND letter a-z"
AND
"replace more than one space with a single space"
?
Currently the code looks like this
<input type="text" size="12" maxlength="12" name="pfWord" id="pfWord"
onkeyup="this.value=this.v
How should I alter the regEx to also say
"allow spaces AND letter a-z"
AND
"replace more than one space with a single space"
?
onkeyup="this.value=this.v alue.repla ce(/[^a-z] [\s]{1,1}/ ig, '')"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
PERFECT Zvonko, thank you!
Mr_Egyptian: this worked, except double spaces were removed rather than replaced with a single space.
Mr_Egyptian: this worked, except double spaces were removed rather than replaced with a single space.