J
J
jkristo ‣2020-06-26 19:34:25
JavaScript
jkristo ‣, 2020-06-26 19:34:25

How to make input validation so that only numbers and (! One) dot or comma would be?

Help refine the regular expression so that using JS and RegExp (probably) to validate the input field so that only numbers or one dot or one comma are entered.
(if there is a semicolon it can't be vice versa)

Here's my solution so far:

<input id = "#inputIn" />
<button id = "#checkIt" >check</button>
<script type = "text/javascript">

document.getElementById("#checkIt").onclick = function () {
    alert(/^\s*[\d]+(?:,[\d]+)?\s*$/.test(document.getElementById("#inputIn").value) );
}

</script>


and link to jsfiddle:
jsfiddle.net/_jack/bgs7n895/7/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
i1yas, 2020-06-26
@jkristo

/^\s*[\d]+([,\.][\d]+)?\s*$/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question