kenwvs Posted July 13, 2006 Share Posted July 13, 2006 These are the functions that I am using in my form. I am not sure if I have written them correctly or not, as I got the gist of it from a tutorial at another site, and then went out on my own. If you want to browse and let me know where I have gone wrong that would be great.I have a feeling this tutorial that is for form validation may not have taken the most direct route, so it may not look totally normal.Thanks in advance,Ken[code]<?phpfunction isDigits($element) { //numbers only return !preg_match ("/[^0-9]/", $element);}?><?phpfunction Dollars($element) { //numbers and decimal return !preg_match ("/[^0-9]./", $element);}?><?phpfunction isLetters($element) { //letters only return !preg_match ("/[^A-z]/", $element);}?><?phpfunction LetandNumOnly($element) { //Letters and Numbers return !preg_match ("/[^A-z0-9]/", $element); //with No Spaces}?><?phpfunction LettersAndDigits($element) { //Letters, Numbers return !preg_match ("/[^A-z0-9 ]/", $element); //and Spaces}?><?phpfunction Variable($element) { //letters, numbers, spaces return !preg_match ("/[^A-z0-9,. ]/", $element);//commas and periods only}?><?phpfunction checkLength($string, $min, $max) { //Check the Length $length = strlen ($string); //min and max if (($length < $min) || ($length > $max)) { return FALSE; } else { return TRUE; }}?><?phpfunction checkMailCode($code, $country) { //Check Postal Code $code = preg_replace("/[\s|-]/", "", $code); //by Country $length = strlen ($code); switch (strtoupper ($country)) { case 'US': if (($length <> 5) && ($length <> 9)) { return FALSE; } return isDigits($code); case 'CA': if ($length <> 6) { return FALSE; } return preg_match ("/([A-z][0-9]){3}/", $code); }}?><?phpfunction checkURL($url) { //check valid URL Format return preg_match ("/http:\/\/(.*)\.(.*)/i", $url);}?><?phpfunction checkURLandConnect($url) { //Check Valid URL and if (!preg_match ("/http:\/\/(.*)\.(.*)/i", $url)) {//Confirm by Connecting return FALSE; } $parts = parse_url($url); $fp = fsockopen($parts['host'], 80, $errno, $errstr, 10); if(!$fp) { return FALSE; } fclose($fp); return TRUE;}?><?phpfunction checkEmail($email) { //Check Email Format $pattern = "/^[A-z0-9\._-]+" . "@" . "[A-z0-9][A-z0-9-]*" . "(\.[A-z0-9_-]+)*" . "\.([A-z]{2,6})$/"; return preg_match ($pattern, $email);}?><?phpfunction EmailorEmpty($email) { //Check Email Format if(empty($email)) { //or empty field return true; } else { $pattern = "/^[A-z0-9\._-]+" . "@" . "[A-z0-9][A-z0-9-]*" . "(\.[A-z0-9_-]+)*" . "\.([A-z]{2,6})$/"; return preg_match ($pattern, $email); }}?><?phpfunction checkPassword($password) { //check password for minimum $length = strlen ($password); //of 8 characters and must if ($length < 8) { //have a number between letters return FALSE; //and a variation of letters } $unique = strlen (count_chars ($password, 3)); $difference = $unique / $length; echo $difference; if ($difference < .60) { return FALSE; } return preg_match ("/[A-z]+[0-9]+[A-z]+/", $password);}?><?phpfunction BidIncrement($bid) {$bid_increment = $_POST['bid_increment']; //function for bid_increment only$item_type = $_POST['item_type'];if($item_type == "auction" or $item_type=="dutch auction"){if(!(is_numeric($bid_increment))OR empty($bid_increment)){ echo "You have not entered a valid Bid Increment"; exit; } else{ echo "Valid bid increment"; }}elseif($item_type == "fixed price" OR $item_type="classified"){ if(!empty($bid_increment)){ echo "Bid Increments are not valid for this type of Listing!";}}?><?phpfunction ReservePrice($reserve) {$reserve_price = $_POST['reserve_price']; //function for reserve_price only$item_type = $_POST['item_type'];if($item_type == "Auction" or $item_type=="Ddutch Auction"){if(!(is_numeric($reserve_price))OR empty($reserve_price)){ echo "You have not entered a Valid Reserve Bid or Starting Price"; exit; } else{ echo "Valid bid increment"; }}elseif($item_type == "Fixed Price" OR $item_type="Classified Ad"){ if(!empty($reserve_price)){ echo "A Reserve Bid or Starting Price cannot be entered for this auction type";}}?><?phpfunction ItemCategory($category) { // Verify Valid Category$item_category = $_POST['item_category'];if($item_category == "000")//assumes you gave it the value 000{echo "Please select a valid category";exit;}}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.