Karabas Posted May 6, 2007 Share Posted May 6, 2007 After using { function valid_name($name) // check ifa name is possibly valid if(ereg("^[A-Z][A-Za-z\ \-]+$", $name)) return true; else return false; } I want a bit more sophistication: 1) capital characters must be preceeded by space 2) space must be followed by a capital letter I tried replacing A-Z in [A-Za-z\ \-]+ by \ A-Z etc but it failed to function as I want. Thank you very much in advance. Quote Link to comment Share on other sites More sharing options...
ashishmat1979 Posted May 17, 2007 Share Posted May 17, 2007 Try with this code function valid_name($name) { // check if a name is possibly valid if(ereg("^[A-Z][a-z-]+([ ]{1}[A-Z]+[a-z-]+)+$", $name)) return true; else return false; } Quote Link to comment Share on other sites More sharing options...
ashishmat1979 Posted May 17, 2007 Share Posted May 17, 2007 Please replace this with previous code bcoz previous code restricts length of words in name to be more than one. function valid_name($name) { // check if a name is possibly valid if(ereg("^[A-Z][a-z-]+([ ]{1}[A-Z]+[a-z-]+)?$", $name)) return true; else return false; } Quote Link to comment Share on other sites More sharing options...
effigy Posted May 17, 2007 Share Posted May 17, 2007 What kind of names are you trying to validate? First, last, or full? 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.