Jump to content

Recommended Posts

I am using this to validate

...elseif ($firstName==""or !ereg("^[A-Za-z' -]{1,30}$",$firstName)){
$message = "Please enter a valid Name";
}

and if I enter a name and then a tag it catches the error eg "Frank</" is not allowed. But if I enter

"Frank&</" it doesn't catch the error although the data is entered into the database as "Frank" which is weird. Why does it do that?

Link to comment
https://forums.phpfreaks.com/topic/68342-validation-problem/
Share on other sites

Well yes that does work but that is pretty much what I have already except I want to also allow a space, a hyphen and an apostrophe so I use

!ereg("^[A-Za-z' -]{1,30}$",$firstName))

My reading of that is that it would allow uppercase and lowercase letters spaces, hyphens and  apostrophes. But it also allows the use of & ...and once the & is used it allows the use of < and / etc.If I don't use the & it doesn't allow < or/.

So my question really is why dose the above expression allow the use of & and how can I exclude it?

Link to comment
https://forums.phpfreaks.com/topic/68342-validation-problem/#findComment-343932
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.