I
I
IvanIvanIvanIvanIvan2018-04-25 10:29:57
JavaScript
IvanIvanIvanIvanIvan, 2018-04-25 10:29:57

How to check if a string contains only numbers?

How to check if the string contains all digits and return false if there are not all digits in the string?

const numberValidator = (val) => {
      let Reg = new RegExp("/^\d+$/");
      return Reg.test(val);
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
l1l1l1, 2018-04-25
@IvanIvanIvanIvanIvan

<script>
    var str = "123456bukva";
    if(!str.match(/^\d+$/)){
        return false;
    }else{
        return true;
    }
</script>

Probably something like this..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question