954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Validation for (.) and (,)

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

if (isNaN(form1.paid.value)) {
   alert ("Syntax is not right.");
   return false;		
}
return true;
veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

Try if(!form1.paid.value.match(/^(\d+|\d*\.(\d+))$/)) .

chaosprime
Light Poster
47 posts since Jul 2008
Reputation Points: 18
Solved Threads: 4
 

No it still returns true for dot.

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

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.

chaosprime
Light Poster
47 posts since Jul 2008
Reputation Points: 18
Solved Threads: 4
 
<script type="text/javascript">
<!--Begin Hiding
function validateForm(form) 
{ 
form = (form.paid.value.indexOf('.') == -1 || form.paid.value.indexOf(',') > 0 ) ?
alert('\nInvalid entry!\nPlease try again...') : alert('Thank you!');
} 
/* 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-->
// Done Hiding -->
</script>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

I solved with checking all the characters bit by bit in textbox, if they are numeric or not.

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You