intl_phone_number_input icon indicating copy to clipboard operation
intl_phone_number_input copied to clipboard

validation not working

Open remymumoh opened this issue 3 years ago • 1 comments

How can you check if the number is not empty, been scratching my head for days. The error is not displayed

  IntlPhoneField(
                                    autovalidateMode: AutovalidateMode.onUserInteraction,
                                    decoration: InputDecoration(
                                      enabledBorder: OutlineInputBorder(
                                        borderRadius: BorderRadius.circular(60),
                                        borderSide: BorderSide(
                                            width: 1.0,
                                            style: BorderStyle.solid,
                                            color: WAPrimaryColor),
                                      ),
                                    ),
                                    inputFormatters: [
                                      FilteringTextInputFormatter.allow(
                                          RegExp("[0-9]"))],
                                    validator: (value) {
                                      if (value == null) {
                                        return 'Please enter your Phone Number';
                                      }
                                      return null;
                                    },
                                    initialCountryCode: 'NG',
                                    keyboardType: TextInputType.number,
                                    onChanged: (value) {
                                      phonenumber = value.number;
                                    },
                                  ),

this doesn't work, i is ignored

remymumoh avatar Feb 18 '22 17:02 remymumoh

Validator passes a String? not a dynamic value. So you should check value.isNotEmpty or value.isEmpty

validator: (phoneNumber) { if (phoneNumber!.isEmpty) { return 'Phone Number Required'; } return null; },

MarcelWilming avatar Nov 09 '22 15:11 MarcelWilming