betamyprice.co.uk Posted June 5, 2008 Share Posted June 5, 2008 Hi all, I am new to this board so firstly may I take the opportunity to say hi. Here's my problem and I'm sure to you guys it is only a small one. I am trying to validate entry into a form. I only want the first name to accept Alphabetic characters, along with apostrophes, hyphens and spaces. From a bit of net research I currently have this: if (!eregi("[_a-zA-Z0-9-]", $_POST[first] )) { $_SESSION['errors'].= "*Your name must be alphabetic" . "<br>"; } But it doesnt work, can someone help please Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Share Posted June 5, 2008 (!eregi("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $_POST["first"]))) { i think! Quote Link to comment Share on other sites More sharing options...
betamyprice.co.uk Posted June 5, 2008 Author Share Posted June 5, 2008 Afraid it doesn't work Runnerjp! But thanks for your efforts. I dropped the extra ) that was throwing an error but it is actually saying that the input is incorrect when it isn't! Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted June 5, 2008 Share Posted June 5, 2008 Try this out. if (!preg_match("/[\w\s-]*/i", $_POST[first] )) { $_SESSION['errors'].= "*Your name must be alphabetic" . "<br>"; } I don't know if ereg will work but I'm pretty sure that preg will. Try it and come back to me. Sorry about the error hope you get this edit please edit your reply if you do. Quote Link to comment Share on other sites More sharing options...
betamyprice.co.uk Posted June 5, 2008 Author Share Posted June 5, 2008 Thanks, I was hopeful but I get this error Fatal error: Call to undefined function pregi() Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted June 5, 2008 Share Posted June 5, 2008 Check the edit sorry for the error. Quote Link to comment Share on other sites More sharing options...
betamyprice.co.uk Posted June 5, 2008 Author Share Posted June 5, 2008 That seems to let everything through you can try for yourself - Fill in the First Name Field http://www.beatmyprice.co.uk/test/rregister.php It is so puzzling isn't it! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 5, 2008 Share Posted June 5, 2008 if (!preg_match("/^[\w\s-]+$/i", $_POST[first] )) Quote Link to comment Share on other sites More sharing options...
betamyprice.co.uk Posted June 5, 2008 Author Share Posted June 5, 2008 Darkwater you are beautiful! Works almost exactly how I want. except i also need to allow for apostrophes for names such as o'Toole Quote Link to comment Share on other sites More sharing options...
dsaba Posted June 5, 2008 Share Posted June 5, 2008 if (!preg_match("/^[\w\s-]+$/i", $_POST[first] )) See Character classes. What exactly are the rules for apostrophes? How many can you have in an approved name..etc.. Where would it be allowed to be placed.. all things to think about. Simply adding ' to the char class should do the trick, but it would also allow for ''''''''''''''''''''''''' to verify just like it already allows for ------------------- to verify. <?php if (!preg_match("/^[\w\s-']+$/i", $_POST[first] )) ?> Quote Link to comment Share on other sites More sharing options...
betamyprice.co.uk Posted June 5, 2008 Author Share Posted June 5, 2008 All over my head I'm afraid my friedn ??? Quote Link to comment Share on other sites More sharing options...
betamyprice.co.uk Posted June 5, 2008 Author Share Posted June 5, 2008 ahhhh it's doing my head in, the form is now passing the ' as \' for example in the o'toole example it is POSTing o/'toole Quote Link to comment Share on other sites More sharing options...
betamyprice.co.uk Posted June 5, 2008 Author Share Posted June 5, 2008 Anybody know how to pass an apostrophe as an apostrophe and not as a forward slash and an apostrophe?? o\'toole Quote Link to comment Share on other sites More sharing options...
effigy Posted June 5, 2008 Share Posted June 5, 2008 It might be magic quotes. Quote Link to comment Share on other sites More sharing options...
MikeDXUNL Posted June 5, 2008 Share Posted June 5, 2008 str_replace('\\', '', $data); that should replace the \' in the data 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.