HighDots Forums  

textbox validation

Javascript JavaScript language (comp.lang.javascript)


Discuss textbox validation in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jothi.v81@gmail.com
 
Posts: n/a

Default textbox validation - 05-19-2008 , 10:42 AM






hi,

i am beginner to java script.

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

Reply With Quote
  #2  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: textbox validation - 05-19-2008 , 11:55 AM






jothi.v81 (AT) gmail (DOT) 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...jects:RegEx p

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


Reply With Quote
  #3  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: textbox validation - 05-19-2008 , 05:42 PM



In comp.lang.javascript message <4831B10F.4080201 (AT) PointedEars (DOT) de>, Mon,
19 May 2008 18:55:43, Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de>
posted:
Quote:
jothi.v81 (AT) gmail (DOT) 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.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.