有没有一种更简单的方法来测试角色,我在前一天看到有关RegExp的一些信息,但是它的应用有所不同,那么我现在正在做什么。该PIONT是例如:JavaScript - 过滤器,RegExp和变量的问题
如果姓名中只包含
a to z
那么返回true如果给定数+1,后来一个当计数为8或更高,将提交后。
但它不工作,当我putin号在名字。
做一些你发现错误的脚本或我可以做得更好?
非常感谢。
var count = 0;
function checkEmail() {
var email = document.getElementById('Email'); // haalt record op en slaat op als variable
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})/; // hier wordt gecheckt of de records correct zijn ingevuld
// hier staat als de test terug komt moet dingen die niet in de filter staat dan voer iets geldig in
if (!filter.test(email.value)) {
alert('Voer geldig email adres in.');
email.focus;// hier wordt gelet als de muis of met die toetsenbord weg gaat van veld
return false;
}
else {
count = count+1;
}
}
function checkVoornaam() {
var voornaam = document.getElementById('voornaam');
var filter = /^([a-zA-Z])/;
if (!filter.test(voornaam.value)) {
alert('Voer uw voornaam in.');
voornaam.focus;
return false;
}
else {
count = count+1;
}
}
function checkachternaam() {
var achternaam = document.getElementById('achternaam');
var filter = /^([a-zA-Z])/;
if (!filter.test(achternaam.value)) {
alert('Voer uw achternaam in.');
achternaam.focus;
return false;
}
else {
count = count+1;
}
}
function checkStraat() {
var straat = document.getElementById('Straatnaam');
var filter = /^([a-zA-Z0-9,#.-]+)/;
if (!filter.test(straat.value)) {
alert('Voer uw straatnaam in.');
straat.focus;
return false;
}
else {
count = count+1;
}
}
function checkSn() {
var sn = document.getElementById('Huisnummer');
var filter = /^([a-zA-Z0-9,#.-]+)/;
if (!filter.test(sn.value)) {
alert('Voer uw huisnummer in.');
sn.focus;
return false;
}
else {
count = count+1;
}
}
function checkPS() {
var ps = document.getElementById('Postcode');
var filter = /^([1-9][0-9]{3}\s?[a-zA-Z]{2})/;
if (!filter.test(ps.value)) {
alert('Voer uw postcode in.');
ps.focus;
return false;
}
else {
count = count+1;
}
}
function checkWP() {
var WP = document.getElementById('Woonplaats');
var filter = /^([a-zA-Z\-']+)/;
if (!filter.test(WP.value)) {
alert('Voer uw woonplaats in.');
WP.focus;
return false;
}
else {
count = count+1;
}
}
function checkTel() {
var tel = document.getElementById('Telefoonnummer');
var filter = /^(\d{3}\d{3}\d{4})/;
if (!filter.test(tel.value)) {
alert('Voer uw telefoonnummer in.');
tel.focus;
return false;
}
else {
count = count+1;
}
}
// global var
var pass1 = document.getElementById('Wachtwoord');
var pass2 = document.getElementById('Herhaal_Wachtwoord');
// functie checkt terplekke of ww1 en ww2 overeenkomen
function checkPass()
{
//Store the Confimation Message Object ...
var message = document.getElementById('confirmMessage');
//Set the colors we will be using ...
var goodColor = "#66cc66";
var badColor = "#ff6666";
//Compare the values in the password field
//and the confirmation field
if(pass1.value == pass2.value){
//The passwords match.
//Set the color to the good color and inform
//the user that they have entered the correct password
pass2.style.backgroundColor = goodColor;
message.style.color = goodColor;
message.innerHTML = "Passwords Match!";
// registreren.register show();
}else{
//The passwords do not match.
//Set the color to the bad color and
//notify the user.
pass2.style.backgroundColor = badColor;
message.style.color = badColor;
message.innerHTML = "Passwords Do Not Match!";
// registreren.register hide();
}
}
function validateForm() {
var fields = ["voornaam", "achternaam", "Email", "Wachtwoord", "Herhaal_Wachtwoord", "Straatnaam", "Huisnummer", "Postcode","Woonplaats","Telefoonummer"];
if (pass1.value !== pass2.value){
alert ("Wachtwoord komen niet overeen");
return false;
}
if (count < 8){
alert("iets is niet goed ingevuld");
return false;
}
var l = fields.length;
var fieldname;
for (i = 0; i < l; i++) {
fieldname = fields[i];
if (document.forms["register"][fieldname].value === "") {
alert(fieldname + " mag niet leeg zijn");
return false;
}
}
// if (count < 8){
// alert("iets is niet goed ingevuld");
// return false;
// }
}
请创建的jsfiddle或plunker。一个工作代码有助于解决问题 – brk
您的描述不太清楚。你能否正确解释你想达到的目标?可能给出一些输出示例。 – Rajesh
你在哪里声明'count',你在哪里检查它的值,你在哪里调用这些函数,以及你在哪里提交表单? – trincot