简体   繁体   中英

How to prevent symbols from being stored in the database using php?

How do I prevent symbols like / , \\ , ; , etc. being stored in the database? I am already using mysql_real_escape_string() , but if in an input field in my form I put \\mymail@mydomain.com , I find the email stored in the database with the "\\". How can I prevent this?

u need to use regular expression to avoid /, \\, ;, etc in data base. use this regular expression. write this javascript.

regExpNum = /^[\w]+(\.[\w]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/
if(!regExpNum.test(EmailID))
{
alert("Invalid email address.");
return false;
}

Maybe you need some kind of input validator like the filter_input (PHP >= 5.2.0)

filter_input(INPUT_GET, 'email', FILTER_VALIDATE_EMAIL);

If the result is null, then, you should send an error.

You could read the documentation at http://www.php.net/manual/en/book.filter.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM