Javascript - Validación básica


/ Published in: PHP
Save to your folder(s)

Se incluye la funcion trim() agregada a completo y emailvalido.


Copy this code and paste it in your HTML
  1. errColor='#F7F7F7';
  2. function trim(str){return str.replace(/^\\s*|\\s*$/g,'');}
  3. function completo(obj,nombre,tipo){if (tipo=='int'){ if ((trim(obj.value)=='')||(isNaN(obj.value))){obj.style.backgroundColor=errColor;return '\\n* '+nombre+' '}else{return '';};}else{ if (trim(obj.value)==''){obj.style.backgroundColor=errColor;return '\\n* '+nombre+'.'}else{return ''}}}
  4. function emailvalido(obj,nombre) {msg = '';if(obj.value!=''){var reg1 = /(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)/;var reg2 = /^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$/;if (reg1.test(obj.value) || !reg2.test(obj.value)){obj.style.backgroundColor=errColor;msg= '\\n* '+nombre+'.'}}else{obj.style.backgroundColor=errColor; msg='\\n* '+nombre+'.'} return msg}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.