我有一个注册表,有“用户名”,“电子邮件”,“密码”字段。 我想只能使用带有“@ mychoice.it”的电子邮件(这只是一个例子)。
var quiz = [{
"question": ["When was the first apple computer made?"],
"choices": ["1904","1976","1978","2004"],
"correct": ["1976"]
}, {
"question": "Who is the founder of Microsoft?",
"choices": ["Bill Gates", "Steve Jobs", "Steve Wozniak" , "Martin Shaba"],
"correct": "Bill Gates"
}, {
"question": "What was your first dream?",
"choices": ["8 bits", "64 bits", "1024 bits"],
"correct": "8 bits"
}, {
"question": "The C programming language was developed by?",
"choices": ["Brendan Eich", "Dennis Ritchie", "Guido van Rossum"],
"correct": "Dennis Ritchie"
}, {
"question": "What does CC mean in emails?",
"choices": ["Carbon Copy", "Creative Commons", "other"],
"correct": "Carbon Copy"
}, {
"question": "What is the full for of IP",
"choices": ["Internet provider", "Intenet Port", "Other","Internet Protocol"],
"correct": "Other"
}];
quiz.forEach(question=>question.choices.scramble());
var score=0;
function ask(index){
index= (index||0) % quiz.length; //let index be valid
var question=quiz[index];
//ask the question
var answer=prompt(question.question+" ["+question.choices.join("] [")+"]");
//exit on false
if(!answer) return alert("Goodbye! Your score is "+score);
//check if user was right
if(answer===question.correct){
alert("Yes. Youre right!");
score++;
}else{
alert("Nope it was "+question.correct);
}
//procceed to the next question
ask(index+1);//next question
}
//lets start
ask(0);
有可能吗?我正在使用bootstrap和PHP。
这是我的表格:
hitoeveryone@mychoice.it -> ok
erika@mychoice.it -> ok
anthony@gmail.it -> NO!!
这是我的PHP脚本进行注册
<form method="post" action="registration.php" >
<div class="form-group" id="form-login" >
<label for="exampleInputEmail1">Indirizzo Email</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="nome.cognomeX@studio.unibo.it" name="Input_Email" required>
</div>
<div class="form-group" id="form-login">
<label for="exampleInputUsername1">Username</label>
<input type="name" class="form-control" id="exampleInputUsername1" placeholder="username" name="Input_Username" required>
</div>
<div class="form-group" id="form-login">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="example_InputPassword1" name="Input_Password" placeholder="password" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
<button type="reset" class="btn btn-default" value="Reset">Reset</button>
答案 0 :(得分:1)
<?php
session_start();
require 'connect.php';
$allowed_domains = array("example.com","example2.com");
if(isset($_POST['Input_Username'])) {
$username = $conn->real_escape_string($_POST['Input_Username']);
}
if(isset($_POST['Input_Email'])) {
$email = $conn->real_escape_string($_POST['Input_Email']);
}
if(isset($_POST['Input_Password'])) {
$password = $conn->real_escape_string($_POST['Input_Password']);
}
$email = explode("@",$email);
if (in_array($email[1],$allowed_domains)) {
$sql = "INSERT INTO utente (Email, Username, Password) VALUES ('$email', '$username', '$password')";
$result = $conn->query($sql);
$conn->close();
header("location:prova.php");
}else{
DO SOMETHING ELSE HERE
}
?>