以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]下面这个如何转变成fox代码?正则表达式提取手机号  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=144021)

--  作者:zto001
--  发布时间:2019/12/8 20:14:00
--  [求助]下面这个如何转变成fox代码?正则表达式提取手机号
下面这个如何转变成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编辑过]

--  作者:有点蓝
--  发布时间:2019/12/8 20:21:00
--  
复制到全局代码即可,前面加上public

public Function ValidatePassword(.....

public Sub TestValidatePassword() ...

--  作者:zto001
--  发布时间: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
--  发布时间:2019/12/8 20:39:00
--  
同时也问下正则表达式提取手机号。
--  作者:有点蓝
--  发布时间: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
--  发布时间:2019/12/9 17:08:00
--  
如果我要在一堆字符串里面,提取手机号,要怎么写?
比如下面这段
大叔大婶多伟1564585421大 打算的15645854214采访人 15sdf6s54df6fs544防守打法 发送到

--  作者:有点蓝
--  发布时间: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