html ve php tarih giriş alanı

2 Cevap php

Ben böyle tarih için bir html giriş kutusu oluşturmak için nasıl anlamaya çalışıyorum sorunlar yaşıyorum:

YYYY-MM-DD

I was wondering if there is a better method of doing this than me manually creating something like this, and then using the - separators to separate the YYYY-MM-DD.

Kullanıcı bu 21 daha büyük olduğundan emin olmak için doğum tarihini girdikten sonra bazı doğrulama yapmak için regex kullanarak olacaktır.

<label for="dob">Age (YYYY-MM-DD)</label>
<input id="dateofbirth" type="text" name="age" maxlength="10"/><span>*</span><br />

İşte php tarafında fonksiyon checkdate içinde olacaktır tarih benim regex olduğunu:

return preg_match('/(\d{4})-(\d{2})-(\d{2})/', $date); 

Set date such that it will only take input from users over 21. Currently this does not.
$date = '1974-12-03';

2 Cevap


if($age = strtotime($date)){ 
 if( ( date('Y',time()) - date('Y',$age ) >= 21 ){
  return true; 
 }else{ 
  return false; } 
}else{ 
 echo 'There seems to be something wrong with your age input'; 
}

Bu kullanıcı üzerinde / 21 yaşını eşit olduğunu doğrular

Ben sadece jquery date picker kullanmak istiyorsunuz.

Bu şekilde giriş biçimi hakkında endişelenmenize gerek yoktur ve kolayca (geri sunucuya tarihini geçirirseniz) javascript veya PHP doğrulama gerçekleştirmek için tek bir formatta girilen tarih alabilirsiniz.