Hi Haji,
Welcome to TSDN...
How accurate are you wanting the validation to be and what are the conditions?
I would assume that the age one is quite simple for example it must be a number, greater than or equal to 0 (incase you have some very young users :)) and less than 120 (unless you have very old users).
The phone number is more involved as it depends on the country that the telephone number is in due to differences in format. If the condition is as simple as it needs to be a number and in a certain length range then this is simple to code, more complex matching can be done using regular expressions to make sure that the submitted phone number matches a pattern.
Sample code for the age (based on the conditions above would be):
-
function checkAge($age){
-
// Create a variable to return, set initial value to false,
-
// this will be changed if the checks are passed.
-
-
var $blAge = false;
-
-
//Check if the $age is a number and not an empty string.
-
if (!isNaN($age) && $age.length>0){
-
-
// Make sure $age within the defined range.
-
if($age>=0 && $age<120){
-
// $age is a valid age so change the return value to true.
-
$blAge=true
-
}
-
}
-
-
//return the return value
-
return $blAge;
-
}
-
The code above creates a function that checks the value passed in and returns true if it is a valid age or false otherwise. The two if conditions could be combined into one, I have put them seperately for clarity.
Please let me know your criteria for the phone number and I can go through that with you.