0

I have a few reg expressions that work on dart but this one for some reason always returns false. I'm trying to validate an ID, code below

 if (RegExp(r'/^[0-9]{3}-[0-9]{4}-[0-9]{7}-[0-9]{1}$/').hasMatch('123-1234-1234567-1')) {
              debugPrint('ID valid');
            } else {
              debugPrint('Invalid');
            }
1
  • 1
    'new' is not necessary in Dart2. Commented Aug 29, 2020 at 10:41

1 Answer 1

1

Drop the slashes, regex delimiters are not needed:

print(RegExp(r'^[0-9]{3}-[0-9]{4}-[0-9]{7}-[0-9]{1}$').hasMatch('123-1234-1234567-1'));

prints true.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.