calmchess Posted April 4, 2013 Share Posted April 4, 2013 I trying to use the following regular exspression to ensure that a number is between 10 and 14 digits but the string returned has null on the end instead of the last number whats wrong ? var pattern4=/^(\d{10}|\d{14})$/ //between 10-14 digits Link to comment https://forums.phpfreaks.com/topic/276542-regex-digits-length-between-10-and-14/ Share on other sites More sharing options...
requinix Posted April 4, 2013 Share Posted April 4, 2013 1. That validates either exactly 10 digits or exactly 14 digits. 2. What "string returned"? Is there more code you haven't shown us? Also: sniped from Psycho Link to comment https://forums.phpfreaks.com/topic/276542-regex-digits-length-between-10-and-14/#findComment-1422957 Share on other sites More sharing options...
Psycho Posted April 4, 2013 Share Posted April 4, 2013 Also: sniped from Psycho I was going to post a quick question such as yours but decided to write a quick example. <html> <head> <script type="text/javascript"> function validNumber(numberStr) { var validNumTest = /^\d{10,14}$/ return validNumTest.test(numberStr); } function testNumber(numberStr) { if(validNumber(numberStr)) { alert('Valid number.'); } else { alert('Not a valid number.'); } } </script> </head> <body> Test Number: <input type="text" id="number1"><br> <button onclick="testNumber(document.getElementById('number1').value);">Check Number</button> </body> </html> Link to comment https://forums.phpfreaks.com/topic/276542-regex-digits-length-between-10-and-14/#findComment-1422958 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.