eXcel的VBA使用正则expression式来validation电子邮件
所以我正在寻找的东西,因为我是新来的正则expression式,是否有可能取代我的“无效”返回语句与类似的声明注释掉在下一行,其中的字符和/或字符#expression失败了。
下面我们使用“msteede48 @ hotmail @ .com”作为myEmailvariables的示例input…
Option Explicit Function ValidEmail(myEmail As String) As String Dim regExp As Object Set regExp = CreateObject("VBScript.Regexp") If Len(myEmail) < 6 Then ValidEmail = "" Else With regExp .Global = True .IgnoreCase = True .Pattern = "^(?=[a-z0-9@.!#$%&'*+/=?^_`{|}~-]{6,254}$)(?=[a-z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?=[a-z0-9-]{1,63}$)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$" End With If regExp.Test(myEmail) = True Then ValidEmail = "Valid" Else ValidEmail = "Invalid" 'ValidEmail = "Error at character:" & CodeToDetermineWhatChar#TheRegexpFailedAtGoesHere & " with a(n):" & CodeToDetermineWhatCharTheRegexpFailedAtGoesHere & "." End If End If Set regExp = Nothing End Function
输出如下所示:字符错误:18(a):@。
- Excel VBA正则expression式检查重复的string
- 如何parsingzip文件中的excel文件?
- 分割string正向斜线与RegExp
- C#正则expression式 – 从Excel公式中获取具有R1C1引用的行数据
- Excel VBA正则expression式:如果以三个空格开始,则将单元格设置为粗体
- 如果相邻单词以相同的字母开头,则用“/”replace空格,否则用“&”ExcelmacrosVBAreplace
- 将Excel中的2个列表与VBA正则expression式进行比较
- Excel正则expression式macros将search一列中的匹配项,将所有匹配的整行粘贴到另一个工作表中
- 在VBA中删除前后单元格中不需要的字符(excel)