Co-authored-by: crazywoola <427733928@qq.com>tags/0.6.12
| def email(email): | def email(email): | ||||
| # Define a regex pattern for email addresses | # Define a regex pattern for email addresses | ||||
| pattern = r"^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$" | |||||
| pattern = r"^[\w\.!#$%&'*+\-/=?^_`{|}~]+@([\w-]+\.)+[\w-]{2,}$" | |||||
| # Check if the email matches the pattern | # Check if the email matches the pattern | ||||
| if re.match(pattern, email) is not None: | if re.match(pattern, email) is not None: | ||||
| return email | return email |
| from libs.helper import email | |||||
| def test_email_with_valid_email(): | |||||
| assert email("test@example.com") == "test@example.com" | |||||
| assert email("TEST12345@example.com") == "TEST12345@example.com" | |||||
| assert email("test+test@example.com") == "test+test@example.com" | |||||
| assert email("!#$%&'*+-/=?^_{|}~`@example.com") == "!#$%&'*+-/=?^_{|}~`@example.com" | |||||
| def test_email_with_invalid_email(): | |||||
| try: | |||||
| email("invalid_email") | |||||
| except ValueError as e: | |||||
| assert str(e) == "invalid_email is not a valid email." | |||||
| try: | |||||
| email("@example.com") | |||||
| except ValueError as e: | |||||
| assert str(e) == "@example.com is not a valid email." | |||||
| try: | |||||
| email("()@example.com") | |||||
| except ValueError as e: | |||||
| assert str(e) == "()@example.com is not a valid email." |
| import Link from 'next/link' | import Link from 'next/link' | ||||
| import Toast from '../components/base/toast' | import Toast from '../components/base/toast' | ||||
| import style from './page.module.css' | import style from './page.module.css' | ||||
| import { IS_CE_EDITION, SUPPORT_MAIL_LOGIN, apiPrefix } from '@/config' | |||||
| import { IS_CE_EDITION, SUPPORT_MAIL_LOGIN, apiPrefix, emailRegex } from '@/config' | |||||
| import Button from '@/app/components/base/button' | import Button from '@/app/components/base/button' | ||||
| import { login, oauth } from '@/service/common' | import { login, oauth } from '@/service/common' | ||||
| import { getPurifyHref } from '@/utils' | import { getPurifyHref } from '@/utils' | ||||
| const validEmailReg = /^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$/ | |||||
| type IState = { | type IState = { | ||||
| formValid: boolean | formValid: boolean | ||||
| const [isLoading, setIsLoading] = useState(false) | const [isLoading, setIsLoading] = useState(false) | ||||
| const handleEmailPasswordLogin = async () => { | const handleEmailPasswordLogin = async () => { | ||||
| if (!validEmailReg.test(email)) { | |||||
| if (!emailRegex.test(email)) { | |||||
| Toast.notify({ | Toast.notify({ | ||||
| type: 'error', | type: 'error', | ||||
| message: t('login.error.emailInValid'), | message: t('login.error.emailInValid'), |
| export const zhRegex = /^[\u4E00-\u9FA5]$/m | export const zhRegex = /^[\u4E00-\u9FA5]$/m | ||||
| export const emojiRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/m | export const emojiRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/m | ||||
| export const emailRegex = /^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$/m | |||||
| export const emailRegex = /^[\w.!#$%&'*+\-/=?^{|}~]+@([\w-]+\.)+[\w-]{2,}$/m | |||||
| const MAX_ZN_VAR_NAME_LENGHT = 8 | const MAX_ZN_VAR_NAME_LENGHT = 8 | ||||
| const MAX_EN_VAR_VALUE_LENGHT = 30 | const MAX_EN_VAR_VALUE_LENGHT = 30 | ||||
| export const getMaxVarNameLength = (value: string) => { | export const getMaxVarNameLength = (value: string) => { |