Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > compare alphanumeric number with integer problem

Reply
Thread Tools

compare alphanumeric number with integer problem

 
 
Matt
Guest
Posts: n/a
 
      09-10-2004
I want to compare the address number in javascript, and the address
number
is alphanumeric. I have a text box and the user needs to enter the
number between 2 numbers as follows (e.g. Please enter the address
number between N11800 and N12800). Note that N11800 and N12800 are
dynamic, it can be pure integers. But this is just an example.

The bug is if the user enter a number that is an integer, for example,
111,
then it still consider as good number. But if I entered A333, then it
has error.

I know I can comment out the following, so that just pure string
comparison. But it sometimes doesn't work.

//if (!isNaN(strValue) && strValue != '')
// strValue = parseInt(strValue);

I guess the wrong I really have no idea what's going on.

Please help. Thanks!!

<html>
<head>
<script type="text/javascript">
function checkField()
{
var startNumber = "N11800";
var endNumber = "N12800";
var strValue = document.InputForm.txtNumber.value;
alert("You entered = " + strValue);
if (!isNaN(strValue) && strValue != '')
strValue = parseInt(strValue);

//just pure string comparisons
if ( strValue == '' || (strValue < startNumber || strValue >
endNumber)){
alert("Please enter a number between " + startNumber + " and " +
endNumber);
InputForm.txtNumber.value = "";
InputForm.txtNumber.focus();
return false;
}
else
{ alert("good number");
return true;
}
}
</script>
</head>
<body>
<FORM NAME="InputForm">
<P>Please enter the address number between N11800 and N12800:
<input type="text" name="txtNumber">
<P><input type="button" value="check field" onClick="checkField()">
</form>
</body>
</html>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Oops! Integer.compare Roedy Green Java 2 05-30-2012 12:18 AM
integer and string compare, is that correct? Hellmut Weber Python 8 01-19-2010 09:15 PM
Int64 outside range of the Integer setting on Compare Validator =?Utf-8?B?Sm9ubyBKb25lcw==?= ASP .Net 3 05-09-2006 09:22 PM
Easier way to determine if a string is an alphanumeric number? fooboo C Programming 9 06-07-2005 10:02 PM
compare alphanumeric problem Matt Javascript 4 09-19-2004 04:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57