Include "space" check in email adress flutter

5,514

Contains works perfectly for me.

void main() {
  bool check;
  String email = 'tes [email protected]';

  check = email.contains(' ');

  print(check); // true
}

I have tried it on DartPad

Perhaps you forgot to put whitespace between quotes.

Share:
5,514
sls
Author by

sls

Updated on December 11, 2022

Comments

  • sls
    sls over 1 year

    Can someone please tell me how to add "space" check in email address? I have tried email.contains("") bt it didnt worked.

    I don't get a error when i type invalid email

     import 'dart:async';
    
    
    class Validators{
      final validEmail = StreamTransformer<String, String>.fromHandlers(
        handleData: (email, sink){
          if(email.contains('@')){
            sink.add(email);
          }else if(email.contains(" ")){
              sink.addError('Enter a valid email');
          }else{
              sink.addError('Enter a valid email');
    
          }
        }
      );
    
      final validPassword  = StreamTransformer<String, String>.fromHandlers(
        handleData: (password, sink){
          if(password.length > 4){
            sink.add(password);
          }else{
            sink.addError('Enter a valid password');
          }
        }
      );
    }
    

    I want "invalid email" error to be displayed as this

    • Eugene
      Eugene almost 5 years
      Can you provide more details about the final result you are trying to achieve and maybe some code? You want to check if the user put only space or you want to detect space at any position in the entered line?
    • sls
      sls almost 5 years
      I want to check if user inserts space in email adress code should return with invalid email adress
  • sls
    sls almost 5 years
    Thank- you for your answer. Can u please look at my code and give answer according to it.
  • Martyns
    Martyns almost 5 years
    @sls Updated answer
  • Randal Schwartz
    Randal Schwartz almost 5 years
    No, see my answer.
  • Randal Schwartz
    Randal Schwartz almost 5 years
    No, see my answer. Space is perfectly valid in an email address if quoted properly.