Foxtable(狐表)用户栏目专家坐堂 → [求助]下面这个如何转变成fox代码?正则表达式提取手机号


  共有2219人关注过本帖树形打印复制链接

主题:[求助]下面这个如何转变成fox代码?正则表达式提取手机号

帅哥哟,离线,有人找我吗?
zto001
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
[求助]下面这个如何转变成fox代码?正则表达式提取手机号  发帖心情 Post By:2019/12/8 20:14:00 [只看该作者]

下面这个如何转变成fox代码?用于验证密码是否复杂

''' <summary>Determines if a password is sufficiently complex.</summary> 
''' <param name="pwd">Password to validate</param> 
''' <param name="minLength">Minimum number of password characters.</param> 
''' <param name="numUpper">Minimum number of uppercase characters.</param> 
''' <param name="numLower">Minimum number of lowercase characters.</param> 
''' <param name="numNumbers">Minimum number of numeric characters.</param> 
''' <param name="numSpecial">Minimum number of special characters.</param> 
''' <returns>True if the password is sufficiently complex.</returns> 
Function ValidatePassword(ByVal pwd As String, _ 
Optional ByVal minLength As Integer = 8, _ 
Optional ByVal numUpper As Integer = 2, _ 
Optional ByVal numLower As Integer = 2, _ 
Optional ByVal numNumbers As Integer = 2, _ 
Optional ByVal numSpecial As Integer = 2) _ 
As Boolean 
' Replace [A-Z] with \p{Lu}, to allow for Unicode uppercase letters. 
Dim upper As New System.Text.RegularExpressions.Regex("[A-Z]") 
Dim lower As New System.Text.RegularExpressions.Regex("[a-z]") 
Dim number As New System.Text.RegularExpressions.Regex("[0-9]") 
' Special is "none of the above". 
Dim special As New System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]") 
' Check the length. 
If Len(pwd) < minLength Then Return False 
' Check for minimum number of occurrences. 
If upper.Matches(pwd).Count < numUpper Then Return False 
If lower.Matches(pwd).Count < numLower Then Return False 
If number.Matches(pwd).Count < numNumbers Then Return False 
If special.Matches(pwd).Count < numSpecial Then Return False 
' Passed all checks. 
Return True 
End Function 
Sub TestValidatePassword() 
Dim password As String = "Password" 
' Demonstrate that "Password" is not complex. 
MsgBox(password & " is complex: " & ValidatePassword(password)) 
password = "Z9f%a>2kQ" 
' Demonstrate that "Z9f%a>2kQ" is not complex. 
MsgBox(password & " is complex: " & ValidatePassword(password)) 
End Sub 
[此贴子已经被作者于2020/3/19 23:14:49编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/12/8 20:21:00 [只看该作者]

复制到全局代码即可,前面加上public

public Function ValidatePassword(.....

public Sub TestValidatePassword() ...

 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2019/12/8 20:36:00 [只看该作者]

应该是问,正则表达式怎么用。

比如
dim 手机号 as string

手机号码:^(13[0-9]|14[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[8|9])\d{8}$

怎么判断是否符合这个正则表达式?



 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2019/12/8 20:39:00 [只看该作者]

同时也问下正则表达式提取手机号。

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/12/8 21:04:00 [只看该作者]

Dim s As String = "13000000000"
Dim p As String = "^(13[0-9]|14[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[8|9])\d{8}$"
Dim rgx = new System.Text.RegularExpressions.Regex(p, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
If rgx.isMatch(s) Then
    msgbox("匹配")
Else
    msgbox("不匹配")
End If

 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2019/12/9 17:08:00 [只看该作者]

如果我要在一堆字符串里面,提取手机号,要怎么写?
比如下面这段
大叔大婶多伟1564585421大 打算的15645854214采访人 15sdf6s54df6fs544防守打法 发送到

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/12/9 17:13:00 [只看该作者]

Dim s As String = "大叔大婶多伟1564585421大 打算的15645854214采访人 15sdf6s54df6fs544防守打法 发送到"
Dim p As String = "(13[0-9]|14[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[8|9])\d{8}"
Dim rgx = new System.Text.RegularExpressions.Regex(p, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
For Each  match As System.Text.RegularExpressions.Match In rgx.Matches(s)
    Output.Show(match.Value )
Next

 回到顶部