Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Large Number Validaton 1

Status
Not open for further replies.

LewisReeder

IS-IT--Management
Jul 18, 2005
38
US
I am trying to validate a very long number. Its more of a code but I need to ensure that it is positive and was entered. The number would look something like this 0012.567.984.01 or 112.345.33333. The problem I am having is that if the user enters more than one decimal point it it is not recorded as a positive number. Any suggestions would be greatly appreciated.

Thanks,
Lewis
 
The problem I am having is that if the user enters more than one decimal point it it is not recorded as a positive number

The 2 examples you posted above have more than 1 decimal point. So does your code need to compensate for more than 1, or is it 1 only?

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Typically it will be more than one decimal point, but it can also be only 1. I am able to handle only one decimal point right now. I run into a problem when trying to validate more than one.

For example:
123.456.789.012
345.678.89
 
Here's a super seksi regexp that will validate both the numbers you posted. There are a few rules with it though:
[li]It must start with a number[/li]
[li]It must end with a number[/li]
[li]You can't have 2 decimals in a row[/li]
Code:
<script language="javascript">
function validateNum(num) {
   alert(/^\d+(\.\d+)*$/.test(num));
}
</script>
<body>
<input type="text" id="txt" />
<br />
<input type="button" value="click me" onclick="validateNum(document.getElementById('txt').value)" />
</body>

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Thanks for the
star.gif


-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top