Validator.js
The Validator.js file is to be included in your HTML, ASP, JSP, or PHP pages. It's a client-side validation file and listed below are the methods that a programmer can call to validate certain data. Note that I will be adding a e-mail validation method in the coming days. There are other methods in the file that can validate certain pieces of data ex: day, month, year. Also there are error handling methods that I will be taking out soon in another version and letting the webpage developer handle the error in their own liking. To include this file just copy and paste this code. <Script language="JavaScript" src="../Validator.js"></Script> Just make sure the file is in the same directory as your webpage. |
Methods | Purpose |
ValidateSSN(ssn) |
Validates a social security number in either XXX-XX-XXXX or XXXXXXXXX format. |
ValidatePhoneNumber(num) |
Validates an American style phone number in either XXX-XXXX, XXXXXXX, XXX-XXX-XXXX, or XXXXXXXXXX formats. |
ValidateTime(time, format) |
Validates the time in HH:MM format. Supports both Standard (1) or Military (2) time formats. |
ValidateAdvancedTime(time, format) |
Just like ValidateTime but it checks for seconds by using this format HH:MM:SS. |
ValidateDate(date, format) |
Validates the date in two formats. US format (1), can be MMDDYY, MM/DD/YY, MM/DD/YYYY, and MMDDYYYY. The international format (2) has YYYY-MM-DD after the date HH:MM:SS. |
ValidateEmailAddr(EmailAddress) |
Validates an email address. Supports .com, .net, .edu, .gov, and .org |
CalculateAge(birthdate) | Calculates an age return a number of years, months, or days depending on how old the person is. If older than one year the age format will be in years, if older than 1 month but less than one year the format will be in months. If born or less than one month the format will be in days. Currently handles MM/DD/YYYY or MMDDYYYY formats. Use the ValidateDate method to make sure the user input is valid before using the CalculateAge method to ensure a valid birthdate and age. |