textbox validation

J

jothi.v81

hi,

i am beginner to java script.

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

Thomas 'PointedEars' Lahn

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/Core_JavaScript_1.5_Reference:Global_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
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Mon,
19 May 2008 18:55:43 said:
(e-mail address removed) wrote:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top