I am using a forms plugin in WordPress that allows for JavaScript queries.
I was told to use something like this: jQuery("#{{elemnt_id}}").val()
In the forms plugin there is a section to input code before submit which is as follows:
// Occurs just before submitting the form
function before_submit() {
// IMPORTANT! If you want to interrupt (stop) the submitting of the form,
this function should return true. You don't need to return any value if you
don't want to stop the submission.
}
I need to validate a serial number based on some minor mathematical equations. The serial number is in the format of: abcd-efghij (in the form of numbers but I am using letters in the format here so that I can explain easier what happens
So the serial number is valid if:
- a is always either the numbers 1 or 2
- bcd is generated further along in step 11
- e is then multiplied by 1
- f is then multiplied by 2
- g is then multiplied by 3
- h is then multiplied by 4
- i is then multiplied by 5
- j is then multiplied by 6
- efghij is then all added up together and multiplied by 3
- a is multiplied by 11 and added to the result of previous step (total of efghij muliplied by 3)
- 3 is then added to the result of that and the result then equals what bcd should be
So a valid number would be something like 1287-123456 because
From second set of digits:
5th digit multiplied by 1:- 1x1=1
6th digit multiplied by 2:- 2x2=4
7th digit multiplied by 3:- 3x3=9
8th digit multiplied by 4:- 4x4=16
9th digit multiplied by 5:- 5x5=25
10th digit multiplied by 6:- 6x6=36
results added all up = 91 (1+4+9+16+25+36)
then multiply by 3:- 91x3=273
Then from first set of digits:
1st digit multiplied by 11:- 1x11=11
Then add result of second set to result of first set:
273 + 11 = 284
and finally add 3 to that:
284 + 3 = 287
giving you 2nd 3rd and 4th digits
I have tried this but its probably totally wrong..
Dim strID
Dim ColCSum3
Dim ChkVal
Dim InitVal
strID = "element_id"
If strID = "" Then
''''' return false
'''' Return "Invalid"
End If
If Mid(strID, 5, 1) <> "-" Or Len(strID) <> 11 Then
'''' return false
'''' Return "Invalid"
End If
InitVal = CLng(Left(strID, 1))
ChkVal = CLng(Mid(strID, 2, 3))
ColCSum3 = (1 * CLng(Mid(strID, 6, 1)) + 2 * CLng(Mid(strID, 7, 1)) + 3 * CLng(Mid(strID, 8, 1)) + 4 * CLng(Mid(strID, 9, 1)) + 5 * CLng(Mid(strID, 10, 1)) + 6 * CLng(Mid(strID, 11, 1))) * 3
If 11 * InitVal + ColCSum3 + 3 = ChkVal Then
Return "Validated"
Else
Return "Invalid"
End If
Any help please for the correct code to use in the form plugin section?