Posted By

nicolaspar on 08/02/06


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

luman
willcodeforfood


Javascript - Validación básica


 / Published in: PHP
 

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

  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  

You need to login to post a comment.