$scope.myCode=function(dynamicField){
console.log("exchangeRate Validator Called");
var regex=new RegExp("^[0-9]*\.?[0-9]{0,6}$");
var regexCornerCase=new RegExp("^[0-9]+\.$"); //if this matches,
//then input has an isuue
if(isNaN(dynamicField.value)){
alert("This value accepts only numbers1");
dynamicField.value=null;
return;
}else{
console.log(regex);
if(regex.test(dynamicField.value)){
if(regexCornerCase.test(dynamicField.value))
{
console.log(regexCornerCase);
alert(dynamicField.value);
alert("This field accepts only numbers2");
dynamicField.value=null;
return;
}
}
else{
alert("This field accepts only numbers");
dynamicField.value=null;
}
}
};
我的使用案例:
dynamicField.value
不应该像'11111'。或'。'。^[0-9]+\.$
似乎不适用于此。