By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

textbox validation

P: n/a
hi,

i am beginner to java script.

i want to validate the textbox that it can accept numers only.and
alphabets only.
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
jo*******@gmail.com wrote:
i am beginner to java script.
It is called JavaScript and has little if anything to do with Java.
i want to validate the textbox that it can accept numers only.and
alphabets only.
<form action="..." ... onsubmit="return validate(this);">
<script type="text/javascript">
function validate(f)
{
var es = f.elements;
if (/\W/.test(es["foo"].value))
{
window.alert("Only numbers and letters, please.");
return false;
}

return true;
}
</script>
...
<input name="foo">
...
</form>

See
http://developer.mozilla.org/en/docs...Objects:RegExp

Look up the Unicode charts for the code points of the glyphs that you
consider part of the alphabet as well (like those of Devanagari, Bengali,
Gujarati or Gurmukhi):

http://unicode.org/charts

The solution can be found plenty of times with your favorite search engine.
Please try that before you post next time.

http://jibbering.com/faq/#FAQ2_3
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 27 '08 #2

P: n/a
In comp.lang.javascript message <48**************@PointedEars.de>, Mon,
19 May 2008 18:55:43, Thomas 'PointedEars' Lahn <Po*********@web.de>
posted:
>jo*******@gmail.com wrote:
>i want to validate the textbox that it can accept numers only.and
alphabets only.
if (/\W/.test(es["foo"].value))
That will, contrary to specification, accept the underline character.
Please think before you write.

It will also reject alphabetic characters such as ij and those
with umlauts; and all Russian Greek, Hangul, etc., letters. But
probably the OP had not intended that they be allowed.
--
(c) John Stockton, nr London UK. ??*@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.