正規表現を取得するパラメーターを使用して関数を実行し、それを使用してフォームのフィールドをチェックします。私はこのコードを持っています:
//The first function handler (no one runs):
field.onblur = function(){
checkField(0, /^([a-z ñáéíóúü]{2,60})$/i, "name", "nameError", "Error in name");
}
//The function:
function checkField(numForm, regex, idField, idError, error){
var form = document.getElementsByTagName("form")[numForm];
var field = form.getElementById(idField);
var spanError = form.getElementById(idError);
//Since here runs, so I think the problem is with the regex
if(!regex.test(idField.value))
spanError.innerHTML = error;
else
spanError.innerHTML = "";
}
関数を作成し、パラメータのような正規表現を与える適切な方法は何ですか?