0

I want to validate a text field for a Identity Card number. ID no has 9 digits and one character. Here is my code. how to do this validation? "code"

Widget buildIDno(){
    return TextFormField(
      decoration: InputDecoration(labelText: 'National Identy Card Number'),
      validator: (String value){
        if(value.isEmpty){
          return 'ID no is Required';
        }
      }
    );
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • 1
    You can use a regular expression to validate the data. But writing a regular expression depends on your card number format. – Midhun MP Apr 27 '20 at 18:17

1 Answers1

0

You could probably do that with regular expressions, take a look here (usage) and here for the official reference.

But a regex pattern in your case could look like that: [0-9]{9}[a-zA-Z]{1} which means that we want to match the group [0-9](= any number between 0 and 9) exactly 9 times and the [a-zA-Z] (= lower- and uppercase letters from A to Z) group just one time.

Also, please use the search engine first before asking a question, as some effort of your own should go into that, we are not here to write your code.

Felipe
  • 80
  • 7