:
在 约翰逊按服务器/客户端标准有效(可能 rfc 5322 )电子邮件地址。也就是说,Gmail和Thunderbird会接受它们。
这个问题地址为完整的电子邮件地址,我不需要:我如何使用正则表达式验证电子邮件地址?
这个不受欢迎的问题是关于JavaScript的,没有答案:验证电子邮件地址的用户名
一部分-An-email-address-indress-in-a-rgular-expression“>上面的第一个问题为完整的电子邮件地址提供了一个可半手的正则 ,我不需要,尽管似乎可能有改进的余地,但我可能不需要改进: https:// stackoverflow。 COM/A/201378/10343144
我目前的最佳解决方案是采用:
emailusername="$1"
testemail="${emailusername}@nonsense.com"
regex='some existing full-email regex'
if [[ "${testemail}" =~ ${regex} ]]; then
echo "it works"
fi
但是,这并不能专门针对电子邮件用户名部分,而且比仅验证用户名部分更昂贵。
是否在用户名中添加一个废话域,以检查最佳方法吗?
还是只能处理电子邮件地址的用户名部分?
In: [email protected]...
I need to make sure that 'johnson' is valid by server/client standards (probably RFC 5322) for the username part of an email address. That is, Gmail and Thunderbird would accept them.
This question addresses full email addresses, which I don't need: How can I validate an email address using a regular expression?
This unpopular question is about JavaScript and doesn't have answers: Validating username part of email address
This answer to the afirst question above offers a semi-acceptable regex for a full email address, which I don't need, though it seems there might be room for improvement, but I might not need improvement: https://stackoverflow.com/a/201378/10343144
My current best solution would be to take:
emailusername="$1"
testemail="${emailusername}@nonsense.com"
regex='some existing full-email regex'
if [[ "${testemail}" =~ ${regex} ]]; then
echo "it works"
fi
But, that doesn't address the email username part specifically, and it's more expensive than validating only the username part.
Is adding a nonsense domain to the username for a regex check the best way?
Or is there a regex that can handle only only the username part of an email address?
发布评论
评论(2)
对于接受的用户名,Gmail比RFC更具限制性(参见创建一个用户名):
备注:用户名的长度未考虑点。
然后,为了使用Bash验证Google用户名:
编辑:遵循@triperee建议,即使用标准壳构造:
Gmail is more restrictive than the RFC in respect of the accepted usernames (see Create a username):
remark: the length of a username doesn't take the dots into account.
Then, for validating a Google username with bash you could do:
Edit: following @tripleee advice, i.e. using standard shell constructs:
如果您的语言环境为
c
以下内容可能对您有用。它的灵感来自您提到的最后一条言论(尚未针对RFC检查),并且没有经过广泛的测试:If your locale is
C
the following may work for you. It is inspired by the last regex you mention (which has not been checked against the RFC), and was not extensively tested: