/*$#################################################$*/
/* 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 username */
/* function CheckPassWord(val,min,max) */
/* Function description: Verify password */
/* function IsSame(val1,val2) */
/* Verify password matching */
/* 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 the 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 value */
/* 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 is true & false (whether it is allowed to be empty) */
/* val form (judged item), va2 form (judged item) */
/* max(max), min(minimum) ...... */
/* Writing time: 2003.09.08.2214 */
/*$#################################################$*/
//Verify string data
function CheckData(valname,val,valimode,limitlen){
if( ("<",0)>0 || (">",0)>0){
alert(valname+"cannot contain < or > characters!.");
();
();
return false;
}
if(valimode==1){
if(isblank()){
alert(valname+"cannot be empty!");
();
();
return false;
}
tmp=new String()
if(istoolong(tmp,limitlen)){
alert(valname+" cannot exceed "+limitlen+" characters!");
();
();
return false;
}
}
else{
tmp=new String()
if(istoolong(tmp,limitlen)){
alert(valname+" cannot exceed "+limitlen+" characters!!");
();
();
return false;
}
}
return true;
}
function isblank(str){
var i;
var len=;
for(i=0;i<len;++i){
if((i)!=" ")
return false;
}
return true;
}
function istoolong(str,i){
var len=;
if(i==0)
return false;
else{
if(len>i)
return true;
else
return false;
}
}
//Verify username
function CheckUserName(val,min,max){
var len = ;
if (len<min || len>max){
alert("The username length is incorrect, it should be "+min+"-"+max+" English letters and numbers.");
();
();
return false;
}
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") && (ch<"a" || ch >"z")){
alert("The username must be composed of lowercase letters or numbers.");
();
();
return false;
}
}
var first =(0)
if (first<"a" || ch >"z"){
alert("The username must start with a lowercase letter.");
();
();
return false;
}
return true;
}
//Verify password
function CheckPassWord(val,min,max){
var len = ;
if (len<min || len>max){
alert("The password length is incorrect, it should be "+min+"-"+max+" English letters and numbers.");
();
();
return false;
}
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") && (ch<"a" || ch >"z")){
alert("The password must be composed of lowercase letters or numbers.");
();
();
return false;
}
}
return true;
}
//Verify password matching
function IsSame(val1,val2){
if ( != ){
alert("The passwords entered twice are different.");
();
();
return false;
}
else
return true;
}
//Verify email
function CheckEmail(val,mode){
if((mode==0) && (=="")){
return true;
}
var etext
var elen
var i
var aa
etext=
elen=
if (elen<5){
alert("Please enter the correct email.");
();
();
return false;
}
i= ("@",0)
if (i==0 || i==-1 || i==elen-1){
alert("Please enter the correct email.");
();
();
return false;
}
else{
if (("@",i+1)!=-1){
alert("Please enter the correct email.");
();
();
return false;
}
}
if (("..",i+1)!=-1){
alert("Please enter the correct email.");
();
();
return false;
}
i=(".",0)
if (i==0 || i==-1 || (elen-1)=='.'){
alert("Please enter the correct email.");
();
();
return false;
}
if ( (0)=='-' || (elen-1)=='-'){
alert("Please enter the correct email.");
();
();
return false;
}
if ( (0)=='_' || (elen-1)=='_'){
alert("Please enter the correct email.");
();
();
return false;
}
for (i=0;i<=elen-1;i++){
aa=(i)
if (!((aa=='.') || (aa=='@') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' && aa<='Z'))){
alert("Please enter the correct email.");
();
();
return false;
}
}
return true;
}
//Verify user height
function CheckValHeight(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct height data.");
();
();
return false;
}
var val2 = ;
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") ){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
}
if (isNaN(val2)){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
else if (parseInt(val2)<=0){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
else if (('0')==0){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
return true;
}
//Verify the user's weight
function CheckValWeight(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct weight data.");
();
();
return false;
}
var val2 = ;
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") ){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
}
if (isNaN(val2)){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
else if (parseInt(val2)<=0){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
else if (('0')==0){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
return true;
}
//Verify the value
function CheckNumber(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct value.");
();
();
return false;
}
var val2 = ;
for (i=1;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9" ) ){
alert("Please enter the correct value.");
();
();
return false;
}
}
if (isNaN(val2)){
alert("Please enter the correct value.");
();
();
return false;
}
else if (('0')==0 && len>1){
alert("Please enter the correct valid value.");
();
();
return false;
}
else if (('-')==0 && ('0')==1){
alert("Please enter the correct valid value.");
();
();
return false;
}
return true;
}
//Verify positive value
function CheckPositive(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
if(!CheckNumber(val,min,max,mode)){
();
();
return false;
}
if (parseInt()<=0){
alert("The data must be a valid positive integer.");
();
();
return false;
}
return true;
}
//Verify negative values
function CheckNegative(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
if(!CheckNumber(val,min,max,mode)){
();
();
return false;
}
if (parseInt()>=0){
alert("The data must be a valid negative integer.");
();
();
return false;
}
return true;
}
//Verify floating point value
function CheckFloat(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct floating point value.");
();
();
return false;
}
var val2 = ;
for (i=1;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9" ) ){
if(ch!="."){
alert("Please enter the correct floating point value.");
();
();
return false;
}
}
}
if (isNaN(val2)){
alert("Please enter the correct floating point value.");
();
();
return false;
}
else if (('0')==0 && ('.')!=1){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
else if (('-')==0 && ('0')==1 && ('.')!=2){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
else if (('-')==0 && ('.')==1){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
else if (('.')==0){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
return true;
}
//Verify file path
function CheckPath(val,mode){
if((mode==0) && (=="")){
return true;
}
var val2 = ;
if ( (':\\')>0 ){
var isNot=" !@#$^*()'`~|]}[{;.>,<?%&+=";
if (('\"')>0){
alert("Please enter the correct file path.");
();
();
return false;
}
else{
for (var i = 0;i < ;i++){
for (var x = 1 ;x < ;x++){
if ((i)==(x)){
alert("Please enter the correct file path.");
();
();
return false;
}
}
}
}
}
else{
alert("Please enter the correct file path.");
();
();
return false;
}
return true;
}
//Verify URL
function CheckURL(val,mode){
if((mode==0) && (=="")){
return true;
}
var val2 = ;
if ( ('://')>0 ){
var isNot=" !@$^*()'`~|]}[{;.>,<";
if (('\"')>0){
alert("Please enter the correct URL.");
();
();
return false;
}
else{
for (var i = 0;i < ;i++){
for (var x = 1 ;x < ;x++){
if ((i)==(x)){
alert("Please enter the correct URL.");
();
();
return false;
}
}
}
}
}
else{
alert("Please enter the correct URL.");
();
();
return false;
}
return true;
}
//Verify the ID card
function CheckChinaIDCard_J(val,mode){
if((mode==0) && (=="")){
return true;
}
sNo = ()
if (!isInteger(sNo)) {
alert("Please enter the correct ID card.");
();
();
return false
}
switch(){
case 15: if (isValidDate((6,2),(8,2),(10,2))) {
return true
}
case 17: if (isValidDate((6,4),(10,2),(12,2))) {
return true
}
}
alert("Please enter the correct ID card.");
();
();
return false
}
function isInteger(sNum) {
var num
num=new RegExp('[^0-9_]','')
if (isNaN(sNum)) {
return false
}
else {
if ((num)>=0) {
return false
}
else {
return true
}
}
}
//Verify Zip
function CheckZip(val,slen,mode){
if((mode==0) && (=="")){
return true;
}
if(!=slen){
alert('Please enter the correct postal code!!');
();
();
return false
}
var r1
r1 = new RegExp('[^0-9]','');
if ( (r1) >= 0 ) {
alert('Please enter the correct postal code!!');
();
();
return false
}
else
return true;
}
Verification of phone number
Require:
(1) Phone number consists of numbers, "(", ")" and "-"
(2) Phone numbers are 3 to 8 digits
(3) If the phone number contains an area code, then the area code is three or four digits
(4) Area codes are separated from other parts by "(", ")" or "-"
(5) The mobile phone number is 11 or 12 digits. If it is 12 digits, then the first digit is 0
(6) The first and second digits of the 11-digit mobile phone number are "13"
(7) The second and third digits of the 12-digit mobile phone number are "13"
According to these rules, the following regular expressions can be drawn:
(^[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}$)
<script language="javascript">
function PhoneCheck(s) {
var str=s;
var reg=/(^[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}$)/
alert((str));
}
</script>
<input type=text name="iphone">
<input type=button onclick="PhoneCheck()" value="Check">
/* 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 username */
/* function CheckPassWord(val,min,max) */
/* Function description: Verify password */
/* function IsSame(val1,val2) */
/* Verify password matching */
/* 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 the 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 value */
/* 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 is true & false (whether it is allowed to be empty) */
/* val form (judged item), va2 form (judged item) */
/* max(max), min(minimum) ...... */
/* Writing time: 2003.09.08.2214 */
/*$#################################################$*/
//Verify string data
function CheckData(valname,val,valimode,limitlen){
if( ("<",0)>0 || (">",0)>0){
alert(valname+"cannot contain < or > characters!.");
();
();
return false;
}
if(valimode==1){
if(isblank()){
alert(valname+"cannot be empty!");
();
();
return false;
}
tmp=new String()
if(istoolong(tmp,limitlen)){
alert(valname+" cannot exceed "+limitlen+" characters!");
();
();
return false;
}
}
else{
tmp=new String()
if(istoolong(tmp,limitlen)){
alert(valname+" cannot exceed "+limitlen+" characters!!");
();
();
return false;
}
}
return true;
}
function isblank(str){
var i;
var len=;
for(i=0;i<len;++i){
if((i)!=" ")
return false;
}
return true;
}
function istoolong(str,i){
var len=;
if(i==0)
return false;
else{
if(len>i)
return true;
else
return false;
}
}
//Verify username
function CheckUserName(val,min,max){
var len = ;
if (len<min || len>max){
alert("The username length is incorrect, it should be "+min+"-"+max+" English letters and numbers.");
();
();
return false;
}
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") && (ch<"a" || ch >"z")){
alert("The username must be composed of lowercase letters or numbers.");
();
();
return false;
}
}
var first =(0)
if (first<"a" || ch >"z"){
alert("The username must start with a lowercase letter.");
();
();
return false;
}
return true;
}
//Verify password
function CheckPassWord(val,min,max){
var len = ;
if (len<min || len>max){
alert("The password length is incorrect, it should be "+min+"-"+max+" English letters and numbers.");
();
();
return false;
}
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") && (ch<"a" || ch >"z")){
alert("The password must be composed of lowercase letters or numbers.");
();
();
return false;
}
}
return true;
}
//Verify password matching
function IsSame(val1,val2){
if ( != ){
alert("The passwords entered twice are different.");
();
();
return false;
}
else
return true;
}
//Verify email
function CheckEmail(val,mode){
if((mode==0) && (=="")){
return true;
}
var etext
var elen
var i
var aa
etext=
elen=
if (elen<5){
alert("Please enter the correct email.");
();
();
return false;
}
i= ("@",0)
if (i==0 || i==-1 || i==elen-1){
alert("Please enter the correct email.");
();
();
return false;
}
else{
if (("@",i+1)!=-1){
alert("Please enter the correct email.");
();
();
return false;
}
}
if (("..",i+1)!=-1){
alert("Please enter the correct email.");
();
();
return false;
}
i=(".",0)
if (i==0 || i==-1 || (elen-1)=='.'){
alert("Please enter the correct email.");
();
();
return false;
}
if ( (0)=='-' || (elen-1)=='-'){
alert("Please enter the correct email.");
();
();
return false;
}
if ( (0)=='_' || (elen-1)=='_'){
alert("Please enter the correct email.");
();
();
return false;
}
for (i=0;i<=elen-1;i++){
aa=(i)
if (!((aa=='.') || (aa=='@') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' && aa<='Z'))){
alert("Please enter the correct email.");
();
();
return false;
}
}
return true;
}
//Verify user height
function CheckValHeight(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct height data.");
();
();
return false;
}
var val2 = ;
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") ){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
}
if (isNaN(val2)){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
else if (parseInt(val2)<=0){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
else if (('0')==0){
alert("Height data must be composed of significant numbers.");
();
();
return false;
}
return true;
}
//Verify the user's weight
function CheckValWeight(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct weight data.");
();
();
return false;
}
var val2 = ;
for (i=0;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9") ){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
}
if (isNaN(val2)){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
else if (parseInt(val2)<=0){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
else if (('0')==0){
alert("Weight data must be composed of significant numbers.");
();
();
return false;
}
return true;
}
//Verify the value
function CheckNumber(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct value.");
();
();
return false;
}
var val2 = ;
for (i=1;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9" ) ){
alert("Please enter the correct value.");
();
();
return false;
}
}
if (isNaN(val2)){
alert("Please enter the correct value.");
();
();
return false;
}
else if (('0')==0 && len>1){
alert("Please enter the correct valid value.");
();
();
return false;
}
else if (('-')==0 && ('0')==1){
alert("Please enter the correct valid value.");
();
();
return false;
}
return true;
}
//Verify positive value
function CheckPositive(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
if(!CheckNumber(val,min,max,mode)){
();
();
return false;
}
if (parseInt()<=0){
alert("The data must be a valid positive integer.");
();
();
return false;
}
return true;
}
//Verify negative values
function CheckNegative(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
if(!CheckNumber(val,min,max,mode)){
();
();
return false;
}
if (parseInt()>=0){
alert("The data must be a valid negative integer.");
();
();
return false;
}
return true;
}
//Verify floating point value
function CheckFloat(val,min,max,mode){
if((mode==0) && (=="")){
return true;
}
var len = ;
if (len<min || len>max){
alert("Please enter the correct floating point value.");
();
();
return false;
}
var val2 = ;
for (i=1;i<;i++){
var ch = (i);
if ( (ch<"0" || ch>"9" ) ){
if(ch!="."){
alert("Please enter the correct floating point value.");
();
();
return false;
}
}
}
if (isNaN(val2)){
alert("Please enter the correct floating point value.");
();
();
return false;
}
else if (('0')==0 && ('.')!=1){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
else if (('-')==0 && ('0')==1 && ('.')!=2){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
else if (('-')==0 && ('.')==1){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
else if (('.')==0){
alert("Please enter the correct valid floating point value.");
();
();
return false;
}
return true;
}
//Verify file path
function CheckPath(val,mode){
if((mode==0) && (=="")){
return true;
}
var val2 = ;
if ( (':\\')>0 ){
var isNot=" !@#$^*()'`~|]}[{;.>,<?%&+=";
if (('\"')>0){
alert("Please enter the correct file path.");
();
();
return false;
}
else{
for (var i = 0;i < ;i++){
for (var x = 1 ;x < ;x++){
if ((i)==(x)){
alert("Please enter the correct file path.");
();
();
return false;
}
}
}
}
}
else{
alert("Please enter the correct file path.");
();
();
return false;
}
return true;
}
//Verify URL
function CheckURL(val,mode){
if((mode==0) && (=="")){
return true;
}
var val2 = ;
if ( ('://')>0 ){
var isNot=" !@$^*()'`~|]}[{;.>,<";
if (('\"')>0){
alert("Please enter the correct URL.");
();
();
return false;
}
else{
for (var i = 0;i < ;i++){
for (var x = 1 ;x < ;x++){
if ((i)==(x)){
alert("Please enter the correct URL.");
();
();
return false;
}
}
}
}
}
else{
alert("Please enter the correct URL.");
();
();
return false;
}
return true;
}
//Verify the ID card
function CheckChinaIDCard_J(val,mode){
if((mode==0) && (=="")){
return true;
}
sNo = ()
if (!isInteger(sNo)) {
alert("Please enter the correct ID card.");
();
();
return false
}
switch(){
case 15: if (isValidDate((6,2),(8,2),(10,2))) {
return true
}
case 17: if (isValidDate((6,4),(10,2),(12,2))) {
return true
}
}
alert("Please enter the correct ID card.");
();
();
return false
}
function isInteger(sNum) {
var num
num=new RegExp('[^0-9_]','')
if (isNaN(sNum)) {
return false
}
else {
if ((num)>=0) {
return false
}
else {
return true
}
}
}
//Verify Zip
function CheckZip(val,slen,mode){
if((mode==0) && (=="")){
return true;
}
if(!=slen){
alert('Please enter the correct postal code!!');
();
();
return false
}
var r1
r1 = new RegExp('[^0-9]','');
if ( (r1) >= 0 ) {
alert('Please enter the correct postal code!!');
();
();
return false
}
else
return true;
}
Verification of phone number
Require:
(1) Phone number consists of numbers, "(", ")" and "-"
(2) Phone numbers are 3 to 8 digits
(3) If the phone number contains an area code, then the area code is three or four digits
(4) Area codes are separated from other parts by "(", ")" or "-"
(5) The mobile phone number is 11 or 12 digits. If it is 12 digits, then the first digit is 0
(6) The first and second digits of the 11-digit mobile phone number are "13"
(7) The second and third digits of the 12-digit mobile phone number are "13"
According to these rules, the following regular expressions can be drawn:
(^[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}$)
<script language="javascript">
function PhoneCheck(s) {
var str=s;
var reg=/(^[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}$)/
alert((str));
}
</script>
<input type=text name="iphone">
<input type=button onclick="PhoneCheck()" value="Check">