erikTsomik
asked on
jquery file name validation
I ma using jquery validation plugin and I need to validate file name so file name should be for example index.htm and nothing else. I tried using the add method but it does not first time around
$.validator.addMethod("fil ename", function(value, element) {
return this.optional(element) || /[a-z]\w*\.(html|htm|swf)$ /i.test(va lue);
}, "Please specify a valid file name");
{
rules: {
file1: {
required: function(element) {
return ($("#locOwner").val()== 0 && $("#server").val()== 0);
},
filename: function(element){
return ($("#userID").val()== 0 && $("#nameID").val()== 0);
}
},
}\}
$.validator.addMethod("fil
return this.optional(element) || /[a-z]\w*\.(html|htm|swf)$
}, "Please specify a valid file name");
{
rules: {
file1: {
required: function(element) {
return ($("#locOwner").val()== 0 && $("#server").val()== 0);
},
filename: function(element){
return ($("#userID").val()== 0 && $("#nameID").val()== 0);
}
},
}\}
ASKER
i did this but still getting an error TypeError: $.validator.methods[method ] is undefined
ASKER
the first time when i click enter the validation does not work , but second it does
>> "i did this but still getting an error..."
what did you do exactly?
The code snippet in the question is not complete enough for me to understand fully.
what did you do exactly?
The code snippet in the question is not complete enough for me to understand fully.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is my full test html. It works for me (in chrome). Try it 'as is' for yourself and see if you get the error with that file.
Q-27840740.html
Q-27840740.html
ASKER
it does not work for me I still able to submit without proper validation. I mean my code is still not working I tried yours and it does
How are you submitting? Is an Ajax call on submit? If so, does that ajax routine check for validation errors before the call.
I am just throwing out ideas as I cannot see you full code.
I am just throwing out ideas as I cannot see you full code.
ASKER
I submit on submit. Also I've notice that I only get this error when i create a record if I come to edit the same record it validates properly without error messages
Oh ... when you "create a record" are you defining it inside a predefined form/inputs or building a new one? If a new one ... the validate may not have been bound to it as it didn't exist on page ready().
ASKER
I think i found the problem . ON the page I have a custom popup that opens up in jquery dialog, and i think it overwrites the javasciprt
ASKER
good work
My example:
Open in new window