943,708 Members | Top Members by Rank

Ad:
Jul 31st, 2008
0

Validation for (.) and (,)

Expand Post »
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;
Similar Threads
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Aug 1st, 2008
0

Re: Validation for (.) and (,)

Try if(!form1.paid.value.match(/^(\d+|\d*\.(\d+))$/)) .
Reputation Points: 18
Solved Threads: 4
Light Poster
chaosprime is offline Offline
46 posts
since Jul 2008
Aug 4th, 2008
0

Re: Validation for (.) and (,)

No it still returns true for dot.
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Aug 4th, 2008
0

Re: Validation for (.) and (,)

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.
Reputation Points: 18
Solved Threads: 4
Light Poster
chaosprime is offline Offline
46 posts
since Jul 2008
Aug 9th, 2008
0

Another solution

javascript Syntax (Toggle Plain Text)
  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>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Aug 10th, 2008
0

Re: Validation for (.) and (,)

I solved with checking all the characters bit by bit in textbox, if they are numeric or not.
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Using onMouseOver in CSS??????
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: how to use escape and unescape





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC