I'm trying to validate the decimal number pattern with specific length but no luck.
I tried this pattern="[0-9]){1,2}(\.){1}([0-9]){2}"
but this works only 12.12
I'm looking for (13digits).(6digits) pattern validation and length validation.
Expected is,
`1234567891123.123456` //true
`1234567891123123456` //false since only number
`12345678911234.123456` //false since 14digits.6digits
`1234567891123.1234567` //false since 13digits.7digits
What be the better regx to fulfill the above validations?
A useful site for regex testing is https://regexr.com/
\b\d{13}\.\d{6}\b
The regex that you need should be like this:
([0-9]){13}(\.){1}([0-9]){6}
So for example in HTML form input, it would look like this:
<form action=""> <input type="text" required pattern="([0-9]){13}(\.){1}([0-9]){6}" /> <button type='submit'>Submit</button> </form>
You can try using this:
\d{13}[.]\d{6}
Working Demo:
var regex = /^[0-9]{13}\.[0-9]{6}$/i; function getValue() { return document.getElementById("myinput").value; } function test() { alert(regex.test(getValue())); }
<input type="text" id="myinput"/> <button id="testBtn" onclick=test()>test</button>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.