/*$############################################# ##$*/
/* Program function: input verification*/
/* Function name: */
/* function CheckData(valname,val,valimode,limitlen) */
/* Function description: Verify string data */
/* function CheckUserName(val,min,max) */
/* Function description: Verify user name*/
/* function CheckPassWord(val,min, max) */
/* Function description: Verify password */
/* function IsSame(val1,val2) */
/* Verify password match*/
/* function CheckEmail(val, mode) */
/* Function description: Verify Email */
/* function CheckValHeight(val,min,max,mode) */
/* Function description: Verify user height*/
/* function CheckValWeight(val,min,max,mode) */
/* Function description: Verify user weight*/
/* function CheckNumber(val,min,max,mode) */
/ * Function description: Verify positive value */
/* function CheckPositive(val,min,max,mode) */
/* Function description: Verify positive value */
/* function CheckNegative(val,min ,max,mode) */
/* Function description: Verify negative values */
/* function CheckFloat(val,min,max,mode) */
/* Function description: Verify floating point values */
/* function CheckPath(val,mode) */
/* Function description: Verify file path*/
/* function CheckURL(val,mode) */
/* Function description :Verify URL */
/* function CheckChinaIDCard_J(val,mode) */
/* Function description: Verify ID card*/
/* function isInteger(sNum) */
/* Function Description: Verify integer */
/* function CheckZip(val,slen,mode) */
/* Function description: Verify Zip */
/* Input parameters: mode true & false (whether allowed to be Empty) */
/* val form (judged item), va2 form (judged item) */
/* max (maximum value), min (minimum value)... */
/* Writing time: 2003.09.08.2214 */
/*$############################## ##################$*/
//Verify string data
function CheckData(valname,val,valimode,limitlen){
if( val.value.indexOf("0 || val.value.indexOf(">",0)>0){
alert(valname "cannot contain characters!. ");
val.focus();
val.select();
return false;
}
if(valimode==1){
if(isblank(val .value)){
alert(valname "Cannot be empty!");
val.focus();
val.select();
return false;
}
tmp=new String(val.value)
if(istoolong(tmp,limitlen)){
alert(valname "cannot exceed" limitlen "characters!");
val.focus();
val.select();
return false;
}
}
else{
tmp=new String(val.value)
if(istoolong(tmp,limitlen) ){
alert(valname "cannot exceed" limitlen "characters!!");
val.focus();
val.select();
return false;
}
}
return true;
}
function isblank(str){
var i;
var len=str.length;
for(i=0;i
return false;
}
return true;
}
function istoolong(str,i) {
var len=str.length;
if(i==0)
return false;
else{
if(len>i)
return true;
else
return false;
}
}
//Verify user name
function CheckUserName(val,min,max){
var len = val.value.length;
if (len
alert("The length of the username is incorrect and should be " min "-" max " English letters and numbers.");
val.focus();
val.select();
return false;
}
for (i=0;i
if ( (ch"9") && (ch"z")){
alert("Username must consist of lowercase letters or numbers. ");
val.focus();
val.select();
return false;
}
}
var first =val.value.charAt(0)
if (first"z"){
alert("Username must start with a lowercase letter.");
val.focus();
val.select();
return false;
}
return true;
}
//Verify password
function CheckPassWord(val,min,max){
var len = val.value.length;
if (len
alert("The password length is incorrect and should be " min "-" max " English letters and numbers.");
val.focus();
val.select();
return false;
}
for (i=0;i
if ( (ch"9") && (ch"z")){
alert("Password must consist of lowercase letters or numbers.");
val.focus();
val.select();
return false;
}
}
return true;
}
//Verify password match
function IsSame(val1,val2){
if (val1.value != val2.value ){
alert("The passwords entered twice are not the same.");
val2.focus();
val2.select();
return false;
}
else
return true;
}
//Verify Email
function CheckEmail(val,mode) {
if((mode==0) && (val.value=="")){
return true;
}
var etext
var elen
var i
var aa
etext=val.value
elen=etext.length
if (elenalert("Please enter the correct email. ");
val.focus();
val.select();
return false;
}
i= etext.indexOf("@",0)
if (i==0 || i==-1 || i==elen-1){
alert("Please enter the correct Email.");
val.focus();
val .select();
return false;
}
else{
if (etext.indexOf("@",i 1)!=-1){
alert("Please enter Correct Email.");
val.focus();
val.select();
return false;
}
}
if (etext.indexOf("..",i 1)!=-1){
alert("Please enter the correct Email.");
val.focus();
val.select();
return false;
}
i=etext.indexOf(".",0)
if (i==0 || i==-1 || etext.charAt(elen-1)=='.'){
alert("Please enter the correct Email.");
val.focus();
val.select();
return false;
}
if ( etext.charAt (0)=='-' || etext.charAt(elen-1)=='-'){
alert("Please enter the correct Email.");
val.focus();
val.select();
return false;
}
if (etext.charAt(0)=='_' || etext.charAt(elen-1)=='_') {
alert("Please enter the correct Email.");
val.focus();
val.select();
return false;
}
for (i =0;iaa=etext.charAt(i)
if (!((aa=='.') || (aa=='@') | | (aa=='-') ||(aa=='_') || (aa>='0' && aa='a' && aa='A' && aaalert("Please enter the correct Email.");
val.focus();
val.select();
return false;
}
}
return true;
}
//Verify user height
function CheckValHeight(val,min,max,mode){
if((mode==0) && ( val.value=="")){
return true;
}
var len = val.value.length;
if (len
alert(" Please enter correct height data. ");
val.focus();
val.select();
return false;
}
var val2 = val.value;
for (i=0; i
if ( (ch"9") ){
alert("Height data must consist of valid digits Composition. ");
val.focus();
val.select();
return false;
}
}
if (isNaN(val2)){
alert("Height data must consist of valid digits.");
val.focus();
val.select();
return false;
}
else if (parseInt (val2)alert("Height data must consist of valid digits.");
val.focus();
val.select();
return false;
}
else if (val2.indexOf('0')==0){
alert("Height data must consist of valid digits.");
val.focus();
val.select();
return false;
}
return true;
}
//Verify user weight
function CheckValWeight(val,min,max,mode){
if((mode==0) && (val.value=="")){
return true;
}
var len = val.value.length;
if ( len
alert("Please enter the correct weight data.");
val.focus();
val.select();
return false;
}
var val2 = val.value;
for (i=0;i
if ( (ch"9") ){
alert("Weight data must consist of valid digits.");
val.focus();
val.select();
return false;
}
}
if (isNaN(val2)){
alert("Weight data must consist of valid digits. ");
val.focus();
val.select();
return false;
}
else if (parseInt(val2)alert ("Weight data must consist of valid digits.");
val.focus();
val.select();
return false;
}
else if (val2.indexOf ('0')==0){
alert("Weight data must consist of valid digits.");
val.focus();
val.select();
return false ;
}
return true;
}
//Verify value
function CheckNumber(val,min,max,mode){
if((mode==0) && ( val.value=="")){
return true;
}
var len = val.value.length;
if (len
alert(" Please enter the correct value. ");
val.focus();
val.select();
return false;
}
var val2 = val.value;
for (i=1;i
if ( (ch"9" ) ){
alert(" Please enter the correct value. ");
val.focus();
val.select();
return false;
}
}
if (isNaN(val2) ){
alert("Please enter the correct value.");
val.focus();
val.select();
return false;
}
else if (val2.indexOf('0')==0 && len>1){
alert("Please enter the correct valid value.");
val.focus();
val.select( );
return false;
}
else if (val2.indexOf('-')==0 && val2.indexOf('0')==1){
alert("Please Enter the correct valid value. ");
val.focus();
val.select();
return false;
}
return true;
}
//Verify positive value
function CheckPositive(val,min,max,mode){
if((mode==0) && (val.value=="")){
return true;
}
if(!CheckNumber(val,min,max,mode)){
val.focus();
val.select();
return false;
}
if (parseInt( val.value)alert("Data must be a valid positive integer.");
val.focus();
val.select();
return false;
}
return true;
}
//Verify negative values
function CheckNegative(val,min,max,mode){
if((mode==0) && ( val.value=="")){
return true;
}
if(!CheckNumber(val,min,max,mode)){
val.focus();
val.select();
return false;
}
if (parseInt(val.value)>=0){
alert("The data must be a valid negative integer.");
val.focus();
val.select();
return false;
}
return true;
}
//Verify floating point value
function CheckFloat(val,min,max,mode){
if((mode==0) && (val.value=="")){
return true;
}
var len = val.value.length;
if (len
alert("Please enter the correct floating point value.");
val.focus();
val.select();
return false;
}
var val2 = val.value;
for (i=1;i
if ( (ch"9" ) ){
if(ch!="."){
alert("Please enter the correct floating point value . ");
val.focus();
val.select();
return false;
}
}
}
if (isNaN(val2)) {
alert("Please enter the correct floating point value.");
val.focus();
val.select();
return false;
}
else if (val2.indexOf('0')==0 && val2.indexOf('.')!=1){
alert("Please enter a correct valid floating point value.");
val. focus();
val.select();
return false;
}
else if (val2.indexOf('-')==0 && val2.indexOf('0')= =1 && val2.indexOf('.')!=2){
alert("Please enter the correct valid floating point value.");
val.focus();
val.select( );
return false;
}
else if (val2.indexOf('-')==0 && val2.indexOf('.')==1){
alert("Please Enter the correct valid floating point value. ");
val.focus();
val.select();
return false;
}
else if (val2.indexOf('.')==0){
alert("Please enter the correct valid floating point value.");
val.focus();
val.select();
return false;
}
return true;
}
//Verify file path
function CheckPath(val,mode){
if((mode==0) && (val.value=="")){
return true;
}
var val2 = val.value;
if ( val2.indexOf(':\')>0 ){
var isNot=" !@#$^*( )'`~|]}[{;.>,%& ="; %& =";
if (val2.indexOf('"')>0){
alert("Please enter the correct file path. ");
val.focus();
val.select();
return false;
}
else{
for (var i = 0;i for (var x = 1 ;x if (val2.charAt(i)==isNot.charAt(x)){
alert( "Please enter the correct file path.");
val.focus();
val.select();
return false;
}
}
}
}
}
else{
alert("Please enter the correct file path.");
val.focus();
val.select();
return false;
}
return true;
}
//Verification URL
function CheckURL(val,mode){
if((mode==0) && (val.value== "")){
return true;
}
var val2 = val.value;
if ( val2.indexOf('://')>0 ){
var isNot= " !@$^*()'`~|]}[{;.>,if (val2.indexOf('"')>0){
alert("Please enter the correct URL. ");
val.focus();
val.select();
return false;
}
else{
for (var i = 0;i for (var x = 1 ;x if (val2.charAt(i)==isNot.charAt(x)){
alert( "Please enter the correct URL.");
val.focus();
val.select();
return false;
}
}
}
}
}
else{
alert("Please enter the correct URL.");
val.focus();
val.select();
return false;
}
return true;
}
//Verify ID card
function CheckChinaIDCard_J(val,mode){
if((mode==0) && (val.value==" ")){
return true;
}
sNo = val.value.toString()
if (!isInteger(sNo)) {
alert("Please enter the correct ID card . ");
val.focus();
val.select();
return false
}
switch(sNo.length){
case 15: if (isValidDate (sNo.substr(6,2),sNo.substr(8,2),sNo.substr(10,2))) {
return true
}
case 17: if (isValidDate(sNo .substr(6,4),sNo.substr(10,2),sNo.substr(12,2))) {
return true
}
}
alert("Please enter correctly ID card.");
val.focus();
val.select();
return false
}
function isInteger(sNum) {
var num
num=new RegExp('[^0-9_]','')
if (isNaN(sNum)) {
return false
}
else {
if (sNum.search(num) >=0) {
return false
}
else {
return true
}
}
}
//Verify Zip
function CheckZip(val ,slen,mode){
if((mode==0) && (val.value=="")){
return true;
}
if(val.value.length! =slen){
alert('Please enter the correct zip code!!');
val.focus();
val.select();
return false
}
var r1
r1 = new RegExp('[^0-9]','');
if ( val.value.search(r1) >= 0 ) {
alert('Please enter Correct zip code!!');
val.focus();
val.select();
return false
}
else
return true;
}
Verification of phone number
Requirements:
(1) The phone number consists of numbers, "(", ")" and "-"
(2) The phone number must be 3 to 8 digits
(3) If the phone number contains an area code, the area code must be three or four digits
(4) The area code should be separated from other parts by "(", ")" or "-"
(5) The mobile phone number is 11 or 12 digits. If it is 12 digits, the first digit is 0
(6) The first and second digits of the 11-digit mobile phone number are "13"
(7) 12 The second and third digits of the mobile phone number are "13"
According to these rules, the following regular expressions can be produced:
(^[0-9]{3,4}-[ 0-9]{3,8}$)|(^[0-9]{3,8}$)|(^([0-9]{3,4})[0-9]{3,8 }$)|(^0{0,1}13[0-9]{9}$)