function check_input (type,required,field) { if (required && field.value.length == 0) { field.className = 'required'; } else if (!required && field.value.length == 0) { field.className = ''; } else if (!validate_input(type,field.value)) { field.className = 'error'; } else { field.className = 'ok'; } } function validate_input(type, value) { switch (type) { case 'email': if (!value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/)) return false; break; case 'ipv4': var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; if (!value.match(ipPattern)) return false; for (i = 0; i < 4; i++) { thisSegment = ipArray[i]; if (thisSegment > 255) return false; } break; case 'subdomain': if (!value.match(/^[\w\-\.]+$/)) return false; break; } return true; }