我希望有人可以帮助我。我们有一个旧的VBScript应用程序正常工作,直到IE 10(和11)发布。应用程序将不再接受Pattern属性。
我们正在检查6种不同的模式,但在这种情况下,我只关注“Phone_2”模式。
有人可以帮我这个吗?
我收到以下错误:
线:32 错误:对象不支持此属性或方法:'thisItem.pattern'
编码:
我的提交按钮
Dim strError
Function doSubmit(frmID)
DIM idArray, numberElements, pattern
strError=""
ReDim idArray(document.all(frmID).length)
For x = 0 to document.all(frmID).length - 1
If document.all(frmID).elements(x).type = "text" or _
document.all(frmID).elements(x).type = "textarea" or _
document.all(frmID).elements(x).type = "hidden" or _
document.all(frmID).elements(x).type = "password" then
pattern=0
set thisItem = document.all(frmID).elements(x)
If lcase(thisItem.validate) <> "none" then
If lcase(thisItem.validate)="regexp" then
pattern=thisItem.pattern
End If
If thisItem.id = "sPassword" then
If document.all(frmID).elements(x+1).id = "sVerifyPass" then
If thisItem.value <> document.all(frmID).elements(x+1).Value then
strError= strError & space(5) & "- Password & Verify not equal" & vbcrlf
idArray(x)=thisItem.id
idArray(x+1)="sVerifyPass"
End If
End If
End If
'Pass the value of the given field, the 'VALIDATE' attribute,
'and the 'PATTERN' attribute to the validateField function
If not validateField(thisItem.value,thisItem.validate,pattern) then
'If the function does not return true, we add the field's
'ID to an array.
idArray(x)=thisItem.id
End If
End If
End If
Next
'strError is defined in the validateField function
If strError <> "" then
For each z in idArray
If z <> "" then
'change the background color of text fields that contain errors
Execute("document.all." & z & ".style.backgroundcolor=""#4ebafa""")
End If
Next
strError="The following errors were found:" & space(5) _
& vbcrlf & vbcrlf & strError
'display errors to user
thisBox = msgBox(strError,16,"Errors Found")
Else
document.all(frmID).submit()
End If
End Function
编码:
For Pattern
Function ValidateField(myValue,myValidate,myPattern)
Dim nonValid, hasChar
myValue=trim(myValue)
SELECT CASE lcase(myValidate)
CASE "regexp" ' use a regular expression
SELECT CASE cstr(myPattern) ' Pattern Types (or your own pattern)
CASE "phone_1"
myPattern="\d{3}-\d{3}-\d{4}$"
myErr="- Phone Number must be in the format: xxx-xxx-xxxx"
CASE "phone_2"
If myValue = "" then
myPattern="()"
Else
myPattern="\d{3}-\d{3}-\d{4}$"
End If
myErr="- Phone Number must be in the format: xxx-xxx-xxxx"
CASE "phone_3"
If myValue = "" then
myPattern="()"
Else
If myValue = "Do Not Call" then
myPattern="Do Not Call"
Else
myPattern="\d{3}-\d{3}-\d{4}$"
End If
End If
myErr="- Phone Number must be in the format: xxx-xxx-xxxx"
CASE "zip_1"
If len(myValue) <= 5 then
myPattern="\d{5}$"
Else
myPattern="\d{5}-\d{4}$"
End If
myErr="- Zip code must be in proper format"
CASE "zip_2"
If myValue = "" then
myPattern="()"
Else
If len(myValue) <= 5 then
myPattern="\d{5}$"
Else
myPattern="\d{5}-\d{4}$"
End IF
End If
myErr="- Zip code must be in proper format"
CASE "acct"
myPattern="\d{4}-\d{4}$"
myErr="- Account must be in the format: xxxx-xxxx"
CASE else
myPattern=myPattern
myErr="- Field did not match the pattern '" & myPattern & "'"
END SELECT
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = myPattern
.IgnoreCase = True
.Global = True
End With
ValidateField = RegularExpressionObject.Test(myValue)
If validateField <> true then
strError= strError & space(5) & myErr & vbcrlf
validation = false
End If
Set RegularExpressionObject = nothing
END SELECT
End Function
以HTML格式调用它:
validate="regexp" pattern="phone_2"
非常感谢提前。