0
$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;
        }
    }
};

My Use case:

  1. the required dynamicField.value should not be like '11111.' or '.'.
  2. My current regex: ^[0-9]+\.$ does not seem to work well for this.
  3. The online regex engines were matching this correctly, but in javascript it didn't.
halfer
  • 19,824
  • 17
  • 99
  • 186
Yogesh Sanchihar
  • 1,080
  • 18
  • 25
  • 2
    `new RegExp("^[0-9]*\.?[0-9]{0,6}$")` -> `/^[0-9]*\.?[0-9]{0,6}$/` || `new RegExp("^[0-9]*\\.?[0-9]{0,6}$")` – Wiktor Stribiżew Apr 19 '17 at 13:54
  • 1
    Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Apr 19 '17 at 15:01

0 Answers0