Welcome visitor
* Login
* Register
It is currently September 15th, 2019, 11:56 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » JavaScript



Post new topic Reply to topic  [ 3 posts ] 
Author Message
  exclude numbers
PostPosted: March 6th, 2009, 2:14 am 
User avatar

Posts: 71
Hello my friends, i have a simple question. I have a form to get the name and age of the user on two separate inputs. What should i do to validate that the name field has no numbers on it and the age input has no letters?

I've thought doing loops, or checking arrays, or matching characters. Also i've found statements like this " /^\d+$/" or "/[a-z]/gi", but since i dont know what they mean im not sure about using them, what are those for? :?:

Thanks


Top
 Profile  
 
  Re: exclude numbers
PostPosted: March 6th, 2009, 2:36 am 
User avatar

Posts: 40
those statements are called regexp-regex-regular expressions, as those from perl.

their structure is like this /regex/modifier.

for example, i would use this to make sure there are only numbers on the 'age' input:
var result = age.match(/\D/);
if (result.length >0){alert ('Only numbers please');}


for no numbers on name you can use this
var result = name.match(/\d/);
if (result.length >0){alert ('No numbers please');}
notice that i didnt use any modifier.

this may not be completely right but at least it can gives you the idea.


Top
 Profile  
 
  Re: exclude numbers
PostPosted: March 6th, 2009, 4:29 am 
User avatar

Posts: 29
To validate only numeric characters on a field I use

if isNaN(age) {
     alert('The age must be a number')
     }
else {
     // PROCESS FORM
     }

_________________
Ooh, I love your magazine. Especially the 'Enrich Your Wordpower' section. I think it's really...really... really...good.
- Homer Simpson


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

FORUMS » Client Side » JavaScript


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron