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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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