跳至内容
菜单
此问题已终结
1 回复
2751 查看

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?

形象
丢弃
最佳答案

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

形象
丢弃
编写者

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/

相关帖文 回复 查看 活动
2
12月 19
24936
0
8月 24
1092
1
12月 19
5351
1
6月 19
13580
1
9月 18
13299