Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation for numbers and alphabets

 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i'm trying to validate only numbers in one input text and to validate only alphabets for another text.

here is the code



i'm getting the input in a text box.
i'm declaring var alpha = /[a-zA-z]/; to specify the a-zA-Z
i might be declaring something like var numb=/0-9/; for numbers.

some text box should get only text and some should get only numbers.
to get only numbers i tried,




stud is the name of my form.
when i run it shows NaN in the output text boxes which should show sum and average and not the alert box.

any help please.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I do not see how you are using alpha

Your regexp would also fail if you were to enter A1 into the textbox.

Eric
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi eric,

yes, it would fail me...
is this expression ok

to check both alpha numerals.

or is there a fundamental mistake i'm making???


thanks in advance
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would still fail



Without giving you the exact answer in code, you are NOT testing the ENTIRE string. You need some +$^ characters in there.

Eric
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what did you come up with?

Eric
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi eric,
not yet..
i have to do it.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic