Check out the LimeSurvey source code on GitHub!

Reverse Regular Expression

More
5 years 9 months ago #58630 by scalprum
I would like to use the reverse regular expression of the following line:

^104[6-8]\s?[a-zA-Z]{2}$

Could someone help me?

Please Log in to join the conversation.

More
5 years 9 months ago - 5 years 9 months ago #58643 by tpartner
What do you mean by "reverse".

A far as I can tell, that regex will search for a string like "1046ab" or "1046 AB". Can you tell us what you would like to search for?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 9 months ago by tpartner.

Please Log in to join the conversation.

More
5 years 9 months ago #58646 by scalprum
I like to search for everything but the string like "1046ab" or "1046 AB".

So the opposite of the regular exprssion: ^104[6-8]\s?[a-zA-Z]{2}$

Thanks!

Please Log in to join the conversation.

More
5 years 9 months ago #58647 by tpartner
As far as I know, there is no "opposite" for regexes.

You will need to use a script like the following to validate against the regex. (replace"QQ" with a text question ID)
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
		var patternMatch = /^104[6-8]\s?[a-zA-Z]{2}$/;
 
		// A listener on the input to validate against the regex
		$('#question'+qID+' input.text').change(function() {
 
			if (patternMatch.test($(this).val()) != true) {
				alert ('Wrong!');
			}
			else {
				alert ('Right!');
			}
		});
 
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form