dartx
                                
                                 dartx copied to clipboard
                                
                                    dartx copied to clipboard
                            
                            
                            
                        [Feature request]Validation String extension
validation extension is also concept?
like this
extension EmailValidator on String {
  bool isValidEmail() {
    return RegExp(
        r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$')
        .hasMatch(this);
  }
  bool isValidHoge() {
     // blah-blah-blah
  }
  // ....
}
If it is. I will do pull-request.
@shinriyo I like the idea. What else could we validate? Emails, URLs, ...
@leisim both of them. and telephone numbers also
@shinriyo Phone numbers are super complicated to validate. I think this should be a separate package (see github.com/google/libphonenumber)
@leisim Thank you. I checked the URL's contents. but, there are not dart languages though it is google official language.
We should avoid adding too many extensions on String. Strings are widely used and most don't represent a phone number or an email address.
For such cases I suggest creating new packages, like an email validator which could also contain validation logic.
final String mailAddress = json["email"] as String;
final EmailAddress email = EmailAddress.tryParse(mailAddress);
if (email != null) {
  print("Email is valid");
}
Side note: Email validation is as tricky as phone number validation. Probably impossible to cover in a single regex. I'd be happy if there is a package with like 100 tests for it 😉