<?php
/*
* To use these functions include this page in your PHP
*
* How to use these functions:
*
* $valid = validateDate($date);
*
* $valid = validateMonthYearDate($date);
*
* $valid = validateStreetAddress($street_address);
*
* @author Stefan Batsas
* @date 2017
*/
/**
* function validates date formats: dd/mm/yyyy, yyyy-mm-dd
* @param type $date
* @return boolean
*/
function validateDate($date) {
$valid = false;
// no support for HTML5 date picker user enters input for date
// any other date format will not pass
if (preg_match("/\d{4}\-\d{2}\-\d{2}/", $date)) {
// if we are here user has entered format of yyyy-mm-dd
$day = $month = $year = "";
// split up the pieces
list($year, $month, $day) = explode("-", $date);
$day = intval($day);
$month = intval($month);
$year = intval($year);
// now use PHP checkdate to verify it is a valid date
if (checkdate($month, $day, $year)) {
$valid = true;
}
// no support for HTML5 date picker user enters input for date
// any other date format will not pass
} else if (preg_match("/\d{2}\/\d{2}\/\d{4}/", $date)) {
// if we are here user has entered format of dd/mm/yyyy
$day = $month = $year = "";
// split up the pieces
list($day, $month, $year) = explode("/", $date);
$day = intval($day);
$month = intval($month);
$year = intval($year);
// now use PHP checkdate to verify it is a valid date
if (checkdate($month, $day, $year)) {
$valid = true;
}
}
return $valid;
}
// end function
/**
* function validates date formats: dd/yyyy, yyyy-mm
* eg. card expiry date
* @param type $date
* @return boolean
*/
function validateMonthYearDate($date) {
$valid = false;
if (preg_match("/\d{4}\-\d{2}/", $date)) {
// if we are here user has ebtered format of mm/yyyy
$month = $year = "";
// split up the pieces
list($year, $month) = explode("-", $date);
$month = intval($month);
$year = intval($year);
// now use PHP checkdate to verify it is a valid date - 1 is supplied for day
if (checkdate($month, 1, $year)) {
$valid = true;
}
// no support for HTML5 date picker user enters input for date
// any other date format will not pass
} else if (preg_match("/\d{2}\/\d{4}/", $date)) {
// if we are here user has ebtered format of mm/yyyy
$month = $year = "";
// split up the pieces
list($month, $year) = explode("/", $date);
$month = intval($month);
$year = intval($year);
// now use PHP checkdate to verify it is a valid date - 1 is supplied for day
if (checkdate($month, 1, $year)) {
$valid = true;
}
}
return $valid;
}
// end function
/**
* Street address example Unit 5/23-24 Page street
* Can contain one forward slash and one dash
* @param type $value
* @return boolean
*/
function validateStreetAddress($value) {
$valid = true;
// check for forward slashes - 1 is permitted
$numSlashes = $numDashes = 0;
// number of slashes replaced stored in $numSlashes
$temp = str_replace("/", "", $value, $numSlashes);
// number of dashes replaced stored in $numSlashes
$temp = str_replace("-", "", $value, $numDashes);
if ($numSlashes > 1 || $numDashes > 1) {
$valid = false;
} else {
// remove spaces
$temp = str_replace(" ", "", $value);
// remove slash
$temp = str_replace("/", "", $temp);
// remove dashes
$temp = str_replace("-", "", $temp);
// check for alpha numeric
if (!ctype_alnum($temp)) {
$valid = false;
} // end if
} // end if
return $valid;
}
// end validation of street address
/**
* Complex names eg Jon-Palo Jnr. the 3rd
* Allow alpha numeric, spaces, 1 hyphen, 1 period, 1 digit
* @param type $value
* @return boolean
*/
function validate_complex_name($value) {
$valid = true;
// remove the spaces
$temp = str_replace(' ', '', $value);
// remove dashes and count them
$temp = str_replace('-', '', $temp, $hyphen_count);
// remove periods and count them
$temp = str_replace('.', '', $temp, $fullstop_count);
// count the number of digits
$digit_count = preg_match_all("/[0-9]/", $temp);
// rules are 1 dash, 1 period, 1 digit and alpha permitted
if (!ctype_alnum($temp) || $hyphen_count > 1 ||
$fullstop_count > 1 || $digit_count > 1) {
$valid = false;
}
return $valid;
}
function validateDOB($value) {
$valid = false;
if (validateDate($value)) {
$today = date('Y-m-d');
$dob = date($value);
$time1 = strtotime($today);
$time2 = strtotime($dob);
if ($time2 < $time1) {
$valid = true;
}
}
return $valid;
}
?>
没有合适的资源?快使用搜索试试~ 我知道了~
PHP中用MVC模式实现数据库的增删改查
共67个文件
php:17个
less:13个
jpg:8个
需积分: 50 11 下载量 76 浏览量
2020-05-10
20:49:45
上传
评论 3
收藏 1.21MB ZIP 举报
温馨提示
此资源为本篇博客源文件。使用MVC模式来实现数据库的增删改查基本操作。其中运用了类的inheritance和implementation等方法,适合初学者学习。
资源推荐
资源详情
资源评论
收起资源包目录
A1P5.zip (67个子文件)
app
view
header.php 3KB
viewBookings.php 2KB
footer.php 966B
search_form.php 922B
content.php 183B
registration_form.php 3KB
factory
PDOFactory.php 565B
controller
HomeController.php 173B
BookingsController.php 4KB
Controller.php 137B
model
DataModel.php 294B
BookingModel.php 2KB
Crudable.php 612B
myfunctions.php 5KB
Validation.php 2KB
database
dbconfig.json 86B
index.php 998B
assets
fonts
glyphicons-halflings-regular.ttf 29KB
glyphicons-halflings-regular.woff 16KB
glyphicons-halflings-regular.svg 62KB
glyphicons-halflings-regular.eot 14KB
js
custom.js 1KB
wow.min.js 3KB
bootstrap.js 54KB
jquery-1.10.2.js 91KB
jquery.min.js 91KB
jquery.easing.min.js 5KB
jquery.scrollTo.js 2KB
bootstrap.min.js 28KB
css
bootstrap.css 120KB
bootstrap.min.css 99KB
animate.css 56KB
style.css 16KB
color
default.css 795B
img
bg1.jpg 772KB
photos
petersjones.jpg 2KB
michellewilliams.jpg 2KB
alicedavison.jpg 2KB
susantaylor.jpg 2KB
XZD5V9O]O7V}NPJ8H{Z0@TX.jpg 567B
henryford.jpg 2KB
johnsmith.jpg 2KB
font-awesome
fonts
fontawesome-webfont.svg 197KB
fontawesome-webfont.eot 37KB
FontAwesome.otf 61KB
fontawesome-webfont.ttf 79KB
fontawesome-webfont.woff 43KB
scss
less
font-awesome.less 405B
variables.less 10KB
icons.less 26KB
stacked.less 476B
rotated-flipped.less 367B
spinning.less 765B
fixed-width.less 119B
list.less 375B
bordered-pulled.less 330B
path.less 684B
larger.less 370B
mixins.less 699B
core.less 270B
css
font-awesome.css 21KB
font-awesome.min.css 17KB
nbproject
project.properties 170B
project.xml 315B
private
config.properties 0B
private.properties 203B
config.php 83B
共 67 条
- 1
资源评论
梦里一声何处鸿
- 粉丝: 507
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功