Jquery validate custom function

is it possible to write a custom function with the jquery validate plugin such as for a password entered in a form to be accepted only if a series of rules apply…to have capital letters,small letters,numbers,punctuation marks.

There is not a jquery.validate method that can handle such a complex rule…
Is it possible though that a custom function can be written for it.

It seems I can write a custom validate function with jquery validate addmethod…

Sure, just validate it using a regex. You can find one written already for you:

You can read more about what Regexs are and how to use them here:

yes,but for what language is the example in stack overflow you gave me?
Are you sure that the code there is javascript?

Regex is regex, whether you use it in javascript, php, html5 patterns or whatever.

1 Like

Though I’m not sure if JS supports lookarounds.

Regular Expressions (regex) are an extremely common way to pattern-match strings. It’s supported by virtually every programming language.

You can learn more about them at this regular expression tutorial.

1 Like

JavaScript supports lookahead, but not lookbehind.

what caught my attention in the example is the fact that I do not see forward slashes(but parentheses).
In the w3schools tutorial the regular expressions are NOT enclosed in parentheses but in forward slashes.

That is the reason I am asking if the code in stack overflow is JS.

That’s because a RegExp itself does not need delimiters. but the languages implementing may need it.

As example in the JS RegExp constructor you do not use delimiters. in PHP the old ereg_* functions didn’t use delimiters either. but delimiters allow you to set flags within the same expression.

1 Like

so what are the delimiters in case of JS…forward slashes?


Are you sure that the code there is javascript?

The first link to SO is language agnostic. The second link fully explains Regexes in a JavaScript context.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.