xiaodao
01-02-2007, 06:34 PM
hi
i have a textfield i want the input be words instead of numbers and symbols
how to do it?
please help
i have a textfield i want the input be words instead of numbers and symbols
how to do it?
please help
|
||||
how to use javascript to valida a text field value is a textxiaodao 01-02-2007, 06:34 PM hi i have a textfield i want the input be words instead of numbers and symbols how to do it? please help Mr J 01-02-2007, 06:56 PM Try this snippet <script type="text/javascript"> <!-- function chkChar(obj){ obj.value = obj.value.replace(/[^a-z\s]/gi,'') } // --> </script> <input type="text" value="" onkeyup="chkChar(this)"> Philip M 01-02-2007, 07:02 PM <HEAD> <SCRIPT type="text/JavaScript"> function validate(f) { if (/[^A-z\s]/gi.test(f.value)) { alert("Only alpha characters and spaces are allowed!"); f.value = f.value.replace(/[^A-z\s]/g,""); } } </SCRIPT> </HEAD> <BODY> <input type="text" onkeyup="validate(this)"> </BODY> There is a typo in Mr J's version:- function chkChar(obj){ obj.value = obj.value.replace(/[^a-z\s]/gi,'') } Mr J 01-02-2007, 07:21 PM I think it was because I used the php tags it lost the backslash There should be a backslash between here \ and here See its gone and lost it again :D So I put my previous post in code tags xiaodao 01-02-2007, 11:33 PM if i also disallow space how Philip M 01-03-2007, 07:46 AM remove \s in both versions:- <HEAD> <SCRIPT type="text/JavaScript"> function validate(f) { if (/[^A-z]/gi.test(f.value)) { alert("Only alpha characters are allowed!"); f.value = f.value.replace(/[^A-z]/g,""); } } </SCRIPT> </HEAD> <BODY> <input type="text" onkeyup="validate(this)"> </BODY> Or in Mr J's version:- function chkChar(obj){ obj.value = obj.value.replace(/[^a-z]/gi,'') } |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum