Jump to content

[SOLVED] Regular expression problem


garethhall

Recommended Posts

Hello I have the  code below and all works great but my name and phone filter doesn't seem to do a very good job. If you place number in the middle of a name it still validate and the same goes for the phone number but with letter in the middle?

// Validation Filters
var emailReg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var nameReg = /[A-Za-z\'\-]/;
var phoneReg = /[0-9\(\)\-\+ ]{7,16}/;

function liveValidation(frmName, fieldName, fieldWhat, apprvMK, rejectMK){
var varReg;
if(fieldWhat == "email"){
	varReg = emailReg;
}else if (fieldWhat == "name"){
	varReg = nameReg;
}else{
	varReg = phoneReg;
}
var fieldVar  = document.forms[frmName].elements[fieldName].value;
var fieldVarName  = document.forms[frmName].elements[fieldName].name

	if(!fieldVar.match(varReg)){
		document.getElementById("spn_"+fieldVarName).innerHTML = "<img src='"+rejectMK+"' width='12' height='12' />";
	}else{
		document.getElementById("spn_"+fieldVarName).innerHTML = "<img src='"+apprvMK+"' width='12' height='12' />";
	}
}

 

Link to comment
https://forums.phpfreaks.com/topic/159971-solved-regular-expression-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.