Validation for (.) and (,)

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Apr 2008
Posts: 496
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

Validation for (.) and (,)

 
0
  #1
Jul 31st, 2008
Hi,

Code below returns true for (.). It should return false like it returns false for (,). Is there any other way to check (.) and (,). I simply want validate money.

Thanks

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. if (isNaN(form1.paid.value)) {
  2. alert ("Syntax is not right.");
  3. return false;
  4. }
  5. return true;
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 46
Reputation: chaosprime is an unknown quantity at this point 
Solved Threads: 4
chaosprime's Avatar
chaosprime chaosprime is offline Offline
Light Poster

Re: Validation for (.) and (,)

 
0
  #2
Aug 1st, 2008
Try if(!form1.paid.value.match(/^(\d+|\d*\.(\d+))$/)) .
Chaos
Lost Souls: text based RPG
MUDseek: MUD gaming search
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 496
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

Re: Validation for (.) and (,)

 
0
  #3
Aug 4th, 2008
No it still returns true for dot.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 46
Reputation: chaosprime is an unknown quantity at this point 
Solved Threads: 4
chaosprime's Avatar
chaosprime chaosprime is offline Offline
Light Poster

Re: Validation for (.) and (,)

 
0
  #4
Aug 4th, 2008
The pattern I posted will only return true for a dot if it has one or more numeric digits after it. Make sure you're actually trying what I posted.
Chaos
Lost Souls: text based RPG
MUDseek: MUD gaming search
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Another solution

 
0
  #5
Aug 9th, 2008
  1. <script type="text/javascript">
  2. <!--Begin Hiding
  3. function validateForm(form)
  4. {
  5. form = (form.paid.value.indexOf('.') == -1 || form.paid.value.indexOf(',') > 0 ) ?
  6. alert('\nInvalid entry!\nPlease try again...') : alert('Thank you!');
  7. }
  8. /* This will validate your form if the user include any of this (',') or exclude one of this ('.') he/she wil be alerted with invalid entry! Hope this one helps you...*///Enjoy-->
  9. // Done Hiding -->
  10. </script>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 496
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

Re: Validation for (.) and (,)

 
0
  #6
Aug 10th, 2008
I solved with checking all the characters bit by bit in textbox, if they are numeric or not.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC