Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 12th, 2002, 04:38 AM
shanor shanor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Israel
Posts: 41 shanor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
regexp newbi prob...

well i guess for u javascript pro's this is too simple...
the thing is this: i have an input type text in my form.
i need a way to verifay that the data in that text filed is just numbers.
Using the isNaN, will work but i need to use regExp....
now, i tried to do something like this:

if (document.myForm.Number.value.search(/[^0-9]) != -1)...

now in this way i get -1 if the value is just numbers. any other cobination of letters or numbers and letters will give a result different than -1.
now, this is just fine exept for one case where the value is empty. in this case i get the result of -1
so insted of having -1 only in case the value is numbers (and only numbers) i get the -1 result in two cases, one, when the value is numbers and second when the value is empty...
in order to solve this i currently check the value to see if its empty, but that makes some of the conditions in my script waaay too long and complicated...
there should be a way to create a regexp that will give one result when the value is only number and a different result in any other case (including a case where the value is empty).
any one??

thnx in advanced.
Shanor.
__________________
You cant see yourself in the mirror with your eyes closed.

Reply With Quote
  #2  
Old November 16th, 2002, 04:51 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
Well, first of all you are posting in the wrong forum, but I will answer your question anyway. Instead of using
Code:
if (document.myForm.Number.value.search(/[^0-9]) != -1)...

try using
Code:
if (document.myForm.Number.value.search(/^[0-9]+$/) != -1))

That regex should tell you if any characters in the string are anything other than 0 thru 9, including an empty string I would think. If anything in the string is other than 0-9 it will return -1. I did not test this, but it *should* work.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > regexp newbi prob...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway