Skip to Content
Menú
This question has been flagged
1 Respondre
2639 Vistes

I have a task to make a registration module with a register form view, inside it I need the fields of email and password to be validated (using regular expressions)


how can I do this?

Avatar
Descartar
Best Answer

Hi,You can do validate the email and password fields using regular expressions according to the below code:
 @api.constrains('email')
    def _check_email(self):
        for record in self:
            if record.email and not re.match(r"[^@]+@[^@]+\.[^@]+", record.email):
                raise ValueError("Invalid email format")

    @api.constrains('password')
    def _check_password(self):
        for record in self:
           if record.password and not re.match(r"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$", record.password):
                raise ValueError("Invalid password format. It must contain at least 8 characters, including one letter and one digit.")


Hope it helps

Avatar
Descartar
Autor

thank you for help. I am wondering if we can have a conversion because I have a couple of questions to be asked.
you can find me on LinkedIn if you have enough time
https://www.linkedin.com/in/dana-kaplan/

Related Posts Respostes Vistes Activitat
2
de des. 19
24827
0
d’ag. 24
1010
1
de des. 19
5241
1
de juny 19
13466
1
de set. 18
13228