CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Sep 2008
    Posts
    16

    REGEX in PHP forms

    I need a regex expression that verifies if a user inputs a valid name (letters and spaces only). However, it doesn't budge.

    Code:
    <?php  
    	function validateInputs(){
    		$status_form = "OK"; $msg="";
    		$fname=$_GET['fname']; $lname=$_GET['lname'];
    		$number=$_GET['number']; $subdivision=$_GET['subdivision'];
    		$street=$_GET['street']; $districtcity=$_GET['districtcity'];
    		$phonenum=$_GET['phonenum']; $cellnum=$_GET['cellnum'];
    		if(!preg_match("/[^A-Za-z\s]/i", $lname)){
    			$status_form="NOTOK";
    			$msg .= "Name format is invalid. Use only alphabets and/or a dash<br>";
    		}
    		if($status_form!="OK"){
    			while (list ($key, $val) = each ($_POST)) $pd .= "$key=".urlencode($val)."&";
    			header ("Location: addentry.php?msg=$msg&$pd"); 
    		} else return true;
    	}
    		
    	if (array_key_exists('add_submit', $_POST)) {
    		if (validateInputs()){
                   
                    }
    		echo "New contact inserted. Details:<br />";
    		echo "<b>FIRST NAME:</b> {$_POST['fname']}<br />";
    		echo "<b>LAST NAME:</b> {$_POST['lname']}<br />";
    		echo "<b>ADDRESS:</b> $addressstring<br />";
    		echo "<b>MOBILE:</b> {$_POST['phonenum']}<br />";
    		echo "<b>PHONE:</b> {$_POST['cellnum']}";
    	} else echo "You can't see this page without submitting the form.";
    ?>
    Last edited by Feebz; October 4th, 2008 at 03:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured