/    Sign up×
Community /Pin to ProfileBookmark

validate a textfield help

do u know how to validate a textfield so that it only accepts letters?

THX

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mrhooJan 06.2007 — This expression returns true or false based on the textboxvalue:

var isonlyletters= /^[a-z]+$/i.test(textboxvalue)

Or, this code prevents anything that isn't an English letter being allowed in the textbox:

[CODE] mytextbox.onkeyup= function(){
var txt= mytextbox.value;
txt= txt.replace(/[^a-zA-Z]/g,'');
mytextbox.value= txt;
}[/CODE]
Copy linkTweet thisAlerts:
@samanyoluJan 06.2007 —  <br/>
&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;

function verifyAlpha(){

var e = document.getElementById('text');

if (!/^[a-zA-Zs]+$/.test(e.value)) { e.value = e.value.substring(0,e.value.length-1);}
}

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

Some alpha: &lt;textarea id="text" onkeyup="verifyAlpha()"&gt;&lt;/textarea&gt;



&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@forty2Jan 06.2007 — <i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function CheckValue(e){
e=(window.event) ? event : e;
return (/[a-zsb]/i.test(String.fromCharCode(e.keyCode)));
} <br/>
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;textarea onkeydown="return CheckValue(event)"&gt;&lt;/textarea&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @littlelion spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...