Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validate number to be numeric
Message
 
 
To
30/04/2009 14:46:38
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
Internet
Category:
Javascript
Miscellaneous
Thread ID:
01397260
Message ID:
01397306
Views:
26
>>Hi everybody,
>>
>>I have a JavaScript to ValidateDate (called ValidateDate). This script is attributed to Einar Kvandahl. I need a similar script to validate number (should only allow integer positive numbers). Is there something built in?
>>
>>Thanks in advance.
>
>I hit up google and found http://acmesoffware.com/acme/ExamplesJS/jsExm_ValidateInteger.asp. Please let me know if you find one that works well because I'm sure I will eventually need one.

Thanks a lot. I already got suggestion of parseInt on another forum, I coded the script, but the little complication is what I'm calling page from ActiveVFP (by Claude Fox).

I'm not yet sure how can I debug it.

This is my whole script for the page now: (stored in a table):

Can not post - UT errors out
where ValidateNumber is
/ *ValidateNumber
  This functions accepts a number string and checks if it's a positive integer.
	
	
	Parameters:
		tcNumber			- The number string you want to verify
		toControl			- The control object that is assosiated with the number
		tcUserMsg			- Massage to display if validation fails. Leave blank if you don't want to notify the user.
		tlStayOnF			- Stay (don't loose focus) on control if validation fails
		tlAllowBlank		-	Allow blank tcNumber passed
		tlBlankOnF		- Blank control value if validation fails
		
	Return:						true or false

	Author: 
	Date: 4/30/2009							 	 	 						 		 			 							*/
function ValidateNumber (tcNumber,toControl,tcUserMsg,tlStayOnF,tlAllowBlank,tlBlankOnF)
{
	focusField=toControl; // Global variable to fix a bug with focus in Firefox when called after an alert.

	if (tlAllowBlank && tcNumber.length==0)
	{
		return true
	}	
	
	
	if (tcUserMsg == 'default')
	{
		tcUserMsg = 'Invalid Input. Please enter valid number';
	}
	
	
	 if(parseInt(tcNumber) > 0)
		return true
         else
	{
	 	if (!(toControl==undefined || toControl=='') && tlBlankOnF){toControl.value = "0"}
		if (!(tcUserMsg==undefined || tcUserMsg=='')){alert(tcUserMsg)}
		if (!(toControl==undefined || toControl=='') && tlStayOnF){setTimeout("focusField.focus();",1);}
		return false
	}

}
Do you see something wrong here?

Thanks.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform