Jump to content
Fórum Script Brasil
  • 0

Checar Entrada De Data (RESOLVIDO)


LuizFumes
 Share

Question

Galera tenho esse script que checa e-mail... o que devo mudar para fazer uma entrada de data no padrão dd/mm/AAAA ??

if (document.frmpesq.pesqdatapara.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)

{

alert("Email inválido");

document.frmpesq.pesqdatapara.focus();

return (false);

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Mais fácil usar uma função pronta:

<!------------- Begin
//-- Original:  Sandeep V. Tamhankar ([email protected]om) 
//-- This script and many more are available free online at 
//-- The JavaScript Source!! http://javascript.internet.com 
// -----------------------------------------------------------------
// Funcao    : IsDateValid
// Linguagem   : JavaScript
// Descricao   : Verifica a validade de uma cadeia de caracteres
// Copyright   : (c) 2000 ADF Consulting - Silvio N Hirashiki
// http://www.adfcon.com.br
// Para usar este script legalmente, mantenha este cabecalho  
// -----------------------------------------------------------------
// Ver    Data    Descricao da alteracao
// --- ---------- --------------------------------------------------
// 1.0            Original: Sandeep V. Tamhankar ([email protected])
// 1.1 2000/04/27 Versao ADF Consulting, para data formato dd/mm/aaaa
// -----------------------------------------------------------------
function IsDateValid(dateStr) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables

	// padrão da data - mostra a quantidade de digitos
	// num ano, mes ou dia
	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{2}|\d{4})$/; //sem o traço...

	// To require a 4 digit year entry, use this line instead:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
  alert("Data em formato inválido ");
  return false
	}

	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[4];

	if (year < 1900 || year > 2078) { 
  //--Verifica intervalo do mes
  alert("O Ano deve estar entre 1900 e 2078");
  return false;
	}

	if (month < 1 || month > 12) { 
  //--Verifica intervalo do mes
  alert("O Mês deve estar entre 1 e 12");
  return false;
	}

	if (day < 1 || day > 31) {
  alert("O Dia deve estar entre 1 e 31.");
  return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
  alert("O Mês "+month+" não tem 31 dias!")
  return false
	}

	if (month == 2) { // check for february 29th
  var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
  if (day>29 || (day==29 && !isleap)) {
  	alert("Fevereiro de " + year + " não tem " + day + " dias!");
  	return false;
    	}
	}
return true;  // date is valid
}
//  End -->

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.7k
    • Total Posts
      648.5k
×
×
  • Create New...