asp隐藏这个字段中,有文字、有数字,如果有数字,超过10为数字的后5位数隐藏

asp隐藏这个字段中,有文字有数字,如果有数字,超过10为数字的后5位数隐藏。

比如,
一个字段保存的内容是:这个字段是文字和数字123444222555内容。
在网页端显示的内容是:这个字段是文字和数字1234442* * * * *内容。

一个字段只有数字,没有文字我会写:
<%
function hide(str)
str = left(str,len(str)-5) + "* * * * *"
hide = str
end function
%>
然后调用这个字段的时候
<%=hide(rsnews("这个字段名称"))%>

但是这个字段有文字,也有数字,怎么能判断呢?
只隐藏超过10位数字的后5位为* * * * *,如果这个数字没有超过10位,就不隐藏。

感谢。

具体需求可留言沟通


Function hide(strng)  '以数组返回
    i = 0
    Set regEx = New RegExp
    regEx.Pattern = "(d+)" '"[0-9]"
    regEx.IgnoreCase = True
    regEx.Global = True
    Set Matches = regEx.Execute(strng)
    For Each Match in Matches
        'RetStr = RetStr &"<br>"& Match.Value
  If  Len(Match.Value)>=10 Then
   strng = Replace(strng, Right(Match.Value,5),"*****")
  End If
        i = i + 1
    Next
    hide = strng
End Function

核心思想是要用正则表达式来读取字符串里的数字

如果是asp可以用 HiddenField隐藏控件

Function RegExpTest(str) 
    Set regEx = New RegExp 
    regEx.Pattern = "(\d+)"
    regEx.IgnoreCase = True 
    regEx.Global = True 
    Set Matches = regEx.Execute(str) 
    For Each Match in Matches 
         If  Len(Match.Value)>=10 Then
           str= Replace(str, Right(Match.Value,5),"*****")
        End If
    Next 
    RegExpTest = str
End Function 
str="你好我是一段字符含有数字和中文1234567890123真的含有123456"
response.write RegExpTest(str)

asp 使用正则提取字符串中的数字,然后判断长度,替换,如有帮助,请点本答案给个采纳

img