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 Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.