function switchtest(fieldval, fieldtype) {
            switch (fieldtype){
                case "email":
                    var atpos = fieldval.indexOf("@");
                    var dotpos = fieldval.lastIndexOf(".");
                    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=fieldval.length) {
                        return [false, "invalid email"]
                    }else{
                        return [true]
                    }
                    break;
                case "file":
                    var validext = [".jpg", ".jpeg", ".png", ".svg"];
                    var extdot = fieldval.lastIndexOf(".");
                    var extension = fieldval.substr(extdot);
                    if($.inArray(extension, validext) != -1){
                        return [true];
                    }else{
                        return [false, "invalid logo image format. Must be 'png', 'jpg/jpeg' and 'svg'."]
                    }
                case "text":
                    if(fieldval.match(/^[a-zA-Z]+$/)){
                        return [true]
                    }else{
                        return [false, "Letter only. No symbols or numbers please."]
                    }
                    break;
                case "password":
                    if(fieldval.length < 8){
                        return [false, "Password must be at least 8 characters long"]
                    }else{
                        return [true]
                    }
                    break;
            }
        }
//validate the field according to its type
validate the field according to its type
validate the field according to its type
function switchtest(fieldval, fieldtype) {
            switch (fieldtype){
                case "email":
                    var atpos = fieldval.indexOf("@");
                    var dotpos = fieldval.lastIndexOf(".");
                    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=fieldval.length) {
                        return [false, "invalid email"]
                    }else{
                        return [true]
                    }
                    break;
                case "file":
                    var validext = [".jpg", ".jpeg", ".png", ".svg"];
                    var extdot = fieldval.lastIndexOf(".");
                    var extension = fieldval.substr(extdot);
                    if($.inArray(extension, validext) != -1){
                        return [true];
                    }else{
                        return [false, "invalid logo image format. Must be 'png', 'jpg/jpeg' and 'svg'."]
                    }
                case "text":
                    if(fieldval.match(/^[a-zA-Z]+$/)){
                        return [true]
                    }else{
                        return [false, "Letter only. No symbols or numbers please."]
                    }
                    break;
                case "password":
                    if(fieldval.length < 8){
                        return [false, "Password must be at least 8 characters long"]
                    }else{
                        return [true]
                    }
                    break;
            }
        }
function switchtest ( fieldval , fieldtype ) { switch ( fieldtype ) { case "email" : var atpos = fieldval . indexOf ( "@" ) ; var dotpos = fieldval . lastIndexOf ( "." ) ; if ( atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= fieldval . length ) { return [ false , "invalid email" ] } else { return [ true ] } break ; case "file" : var validext = [ ".jpg" , ".jpeg" , ".png" , ".svg" ] ; var extdot = fieldval . lastIndexOf ( "." ) ; var extension = fieldval . substr ( extdot ) ; if ( $ . inArray ( extension , validext ) != - 1 ) { return [ true ] ; } else { return [ false , "invalid logo image format. Must be 'png', 'jpg/jpeg' and 'svg'." ] } case "text" : if ( fieldval . match ( / ^[a-zA-Z]+$ / ) ) { return [ true ] } else { return [ false , "Letter only. No symbols or numbers please." ] } break ; case "password" : if ( fieldval . length < 8 ) { return [ false , "Password must be at least 8 characters long" ] } else { return [ true ] } break ; } }
validate the field according to its type
validate the field according to its type