I need to validate the user input using regular expression. It should be a number with 6 or 7 digit (between 0-9), no trailing and leading spaces should be allowed. Currently i am using ^\d{6,7} the problem here is even if i type 6 or 7 digits am getting the error message.
Can anyone help me?
The correct regex would be
^\d{6,7}$or the user would be able to put more than 7 digits.You are doing a bad coding, because even your regex should match 6-7 digits.
RegExr link