C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » General »

Positive Whole number validation ....


Posted Date: 12 Feb 2007    Resource Type: Articles    Category: General
Author: RamarajSundaramMember Level: Diamond    
Rating: 1 out of 5Points: 7



Introduction:
This article provides a solution for positive whole number validation using JavaScript.
Solution:
We can predict the positive whole numbers using the following JavaScript function.

function isPositiveInteger(){
if(val==null){return false;}
if (val.length==0){return false;}
for (var i = 0; i < val.length; i++) {
var ch = val.charAt(i)
if (ch < "0" || ch > "9") {
return false
}
}
}

The above function simply accepts any value (as a parameter value) into the variable “val”. The first “if” statement in the function “isPositiveInteger” simply checks for “null”. The second “if” statement in the same function counts the number of characters available. If no characters are found, it returns “false”.
If any characters are found, we go through each character (using a “for” loop) and check whether the character is NOT within the range of “0” through “9” (based on ASCII). If any character is found, we return false. Finally, we return “true” if no other character apart from digits is found.
Summary:
This article will be very useful to validate the positive whole numbers.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Whole number  .  Validation  .  Positive  .  Javascript  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: TOP TEN TECHNOLOGY PREDICTIONS FOR 2007
Previous Resource: Approach to DATE field in a Different Way [ASP & JavaScript]
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use