Connecting Tech Pros Worldwide Forums | Help | Site Map

textbox validation

jothi.v81@gmail.com
Guest
 
Posts: n/a
#1: Jun 27 '08
hi,

i am beginner to java script.

i want to validate the textbox that it can accept numers only.and
alphabets only.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#2: Jun 27 '08

re: textbox validation


jothi.v81@gmail.com wrote:
Quote:
i am beginner to java script.
It is called JavaScript and has little if anything to do with Java.
Quote:
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
Dr J R Stockton
Guest
 
Posts: n/a
#3: Jun 27 '08

re: textbox validation


In comp.lang.javascript message <4831B10F.4080201@PointedEars.de>, Mon,
19 May 2008 18:55:43, Thomas 'PointedEars' Lahn <PointedEars@web.de>
posted:
Quote:
>jothi.v81@gmail.com wrote:
Quote:
Quote:
>i want to validate the textbox that it can accept numers only.and
>alphabets only.
Quote:
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.
Closed Thread