jnvnsn Posted July 11, 2011 Share Posted July 11, 2011 var NumberToTest = 1234; var IsFound = /^\d+$/.test(NumberToTest); document.write(IsFound); Help anyone on how to restrict 4 digits. This works but it is true even though how many digits is being entered. HELP Quote Link to comment https://forums.phpfreaks.com/topic/241700-validating-4-digitshelp/ Share on other sites More sharing options...
Adam Posted July 11, 2011 Share Posted July 11, 2011 Remove the plus, which means 1 or more, and add "{4}". That will require exactly 4 repetitions of the token.. /^\d{4}$/ Quote Link to comment https://forums.phpfreaks.com/topic/241700-validating-4-digitshelp/#findComment-1241356 Share on other sites More sharing options...
jnvnsn Posted July 11, 2011 Author Share Posted July 11, 2011 Thank You MrAdam! One more thing, where can i find good tutorial about this? Quote Link to comment https://forums.phpfreaks.com/topic/241700-validating-4-digitshelp/#findComment-1241365 Share on other sites More sharing options...
Adam Posted July 11, 2011 Share Posted July 11, 2011 http://www.regular-expressions.info/tutorial.html Quote Link to comment https://forums.phpfreaks.com/topic/241700-validating-4-digitshelp/#findComment-1241366 Share on other sites More sharing options...
jnvnsn Posted July 11, 2011 Author Share Posted July 11, 2011 Been a great help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/241700-validating-4-digitshelp/#findComment-1241369 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.