Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- DEFINE ("DB_HOST","localhost");
- DEFINE ("DB_USER","root");
- DEFINE ("DB_PASS","");
- DEFINE ("DB_SITE","pcm");
- //Validators//
- function validateUsername($txtID)
- {
- if ($txtID == null)
- {
- return 'Please enter <strong>Username</strong>.<br/>';
- }
- else if (!preg_match("/^[0-9a-zA-Z_]{5,}$/",$txtID))
- {
- return '<strong>Username</strong> is invalid please read the following instruction.<br/>';
- }
- else if (UsernameExist($txtID))
- {
- return '<strong>Username</strong> given already exist. Try another.<br/>';
- }
- }
- function validatePassword($txtPassword)
- {
- if ($txtPassword == null)
- {
- return 'Please enter <strong>Password</strong>.<br/>';
- }
- else if (!preg_match("/^.*(?=.{5,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/",$txtPassword))
- {
- return '<strong>Password</strong> is invalid please read the following instruction.<br/>';
- }
- }
- function validateConfirmPassword($txtConfirmPassword)
- {
- if ($txtConfirmPassword == null)
- {
- return 'Please Confirm <strong>Password</strong>.<br/>';
- }
- else if ($txtConfirmPassword != $_REQUEST['txtPassword'])
- {
- return 'The confirm password is not match with the password.<br/>';
- }
- }
- function validateName($txtName)
- {
- if ($txtName == null)
- {
- return 'Please enter your <strong>Full Name</strong>.<br/>';
- }
- else if(strlen($txtName) > 30)
- {
- return 'Character Cannot More Than 30 word.<br/>';
- }
- else if(!preg_match("/^[A-Z][a-zA-Z -]+$/",$txtName))
- {
- return '<strong>Name</strong> is invalid please read the following.<br/>';
- }
- }
- function validateAddress($txtAddress)
- {
- if ($txtAddress == null)
- {
- return 'Please enter your <strong>Address</strong>.<br/>';
- }
- }
- function validateDOB($txtDOB)
- {
- if ($txtDOB == null)
- {
- return 'Please enter your <strong>Date of Birth</strong>.<br/>';
- }
- else if(!preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/",$txtDOB))
- {
- return '<strong>Date of Birth</strong> is invalid please read the following.<br/>';
- }
- }
- function validateGender($gender)
- {
- if ($gender == null)
- {
- return 'Please enter your <strong>Gender</strong>.<br/>';
- }
- }
- function validateEmail($txtEmail)
- {
- if ($txtEmail == null)
- {
- return 'Please enter your <strong>Email</strong>.<br/>';
- }
- else if(!preg_match("/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/",$txtEmail))
- {
- return '<strong>Email</strong> is invalid please read the following.<br/>';
- }
- else if (EmailExist($txtEmail))
- {
- return '<strong>Email</strong> given already exist. Try another.<br/>';
- }
- }
- function UsernameExist($txtID)
- {
- $exist = false;
- $con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_SITE);
- $id = $con->real_escape_string($txtID);
- $sql = "SELECT * FROM member WHERE UserName = '$txtID'";
- if ($result = $con->query($sql))
- {
- if ($result->num_rows > 0)
- {
- $exist = true;
- }
- }
- $result->free();
- $con->close();
- return $exist;
- }
- function EmailExist($txtEmail)
- {
- $exist = false;
- $con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_SITE);
- $id = $con->real_escape_string($txtID);
- $sql = "SELECT * FROM member WHERE Email = '$txtEmail'";
- if ($result = $con->query($sql))
- {
- if ($result->num_rows > 0)
- {
- $exist = true;
- }
- }
- $result->free();
- $con->close();
- return $exist;
- }
- ?>
Add Comment
Please, Sign In to add comment