【发布时间】:2017-04-27 13:36:20
【问题描述】:
public static bool CheckFields(AS_AccountInfo regInfo, string passwordConfirm,
string emailConfirm, ref string errorMessage)
{
errorMessage = "";
// Validate the data in the fields (make sure it matches their type
if ( !regInfo.fields.CheckMySQLFields (ref errorMessage) )
return false;
if (regInfo.GetFieldValue("password") == null ||
(AS_Preferences.askUserForEmail && regInfo.GetFieldValue("email") == null))
{
errorMessage = "Account info not set up correctly..! Missing fields..!";
return false;
}
// Password must match
if (regInfo.GetFieldValue ("password") != passwordConfirm) {
errorMessage = "Passwords must match..!";
return false;
}
// If an email has been entered
else if (AS_Preferences.askUserForEmail && regInfo.GetFieldValue ("email") != "") {
// It must be valid
if (!new Regex (@"^[\w!#$%&*+\-/=?\^_`{|}~]+(\.[\w!#$%&*+\-/=?\^_`{|}~]+)*@"
+ "@leeds.ac.uk").Match (regInfo.GetFieldValue ("email")).Success) {
errorMessage = "Invalid email..!";
return false;
}
// And match its confirm
if (regInfo.GetFieldValue ("email") != emailConfirm) {
errorMessage = "Emails must match..!";
return false;
}
}
// All good..!
return true;
}
<? php
$link = try_mysql_connect($databaseHostname, $databaseUsername,
$databasePassword, $databaseDbName, $databasePort);
$from = $emailAccount;
$info = $_POST['newAccountInfo'];
$requireEmailActivation = strtolower($_POST['requireEmailActivation']);
$fields = explode($fieldsSeparator, $info);
$fieldNames = "";
$fieldValues = "";
$email = "";
foreach ($fields as $field) {
$words = explode($fieldNameValueSeparator, $field);
$fieldName = $words[0];
$fieldValue = $words[1];
$fieldName = stripslashes($fieldName);
$fieldValue = stripslashes($fieldValue);
$fieldName = mysqli_real_escape_string($link,$fieldName);
$fieldValue = mysqli_real_escape_string($link,$fieldValue);
if ($fieldName == "")
continue;
}
if ($requireEmailActivation == "true") {
if ($fieldName == "username")
$username = $fieldValue;
if ($fieldName == "email"){
$email = $fieldValue;
}
// Store it
$fieldNames .= "`$fieldName`,";
if ($fieldValue == "")
$fieldValues .= "NULL,";
else
$fieldValues .= "'$fieldValue',";
}
$fieldNames = rtrim( $fieldNames, ",");
$fieldValues = rtrim( $fieldValues, ",");
$query = "INSERT INTO accounts
(" . $fieldNames .")
VALUES ( " . $fieldValues . " )";
try_mysql_query($link, $query);
?>
结果:
MySQL 错误 1054(“字段列表”中的“未知列”) 执行时
INSERT INTO accounts (``) VALUES ( NULL )
有人能解释一下吗?我试图对表达式中的各种字符进行分隔,但仍然没有成功。在我看来,reg 表达式应该可以工作,它只是 leeds.ac.uk 元素,它被绊倒了,但我不知道为什么?
【问题讨论】:
-
你在哪里使用/存储正则表达式?
-
NB 我知道这不能防止注射!!!
-
然而,在哪里使用这个正则表达式作为文字字符串或函数参数并不明显。
-
道歉我现在已经包含了更多信息@revo
标签: javascript c# php regex