Stop jQuery blur event inside blur function

I have a text box in which I use the blur event to validate text with a regular expression. If this fails, I want the text box to keep focus. I know that in regular javascript you can say return functionName();in the onblur event inside the current html control. Is there a way to do something similar when binding a blur event inside a function $(document).ready(). Or just set the focus to "this". Thanks for the help.

$(document).ready(function() {");
    $('input:text.sqlValidation').blur(function() {");
        var sqlInjectionRegX2 = /...Regex.../;
        var value = this.value;
        if (sqlInjectionRegX2.test(value)) {
            alert('The text you have entered may contain malicious code and can not be submitted.');
            this.value = '';
            return false;
        }
        else return true;
    });
});
+3
source share
5 answers

Javascript SQL - (, , ) . !!! . , , . SQL Injection , , , , . , , Javascript ( HTTP-), . , , SQL- .


, return false event.preventDefault() . ; , , Javascript.

+6
+3

- - javascript, ;

:

var inBlur = false;
jQuery('#the_input_element').blur(function(){
    if (!inBlur) {
        inBlur = true;
        jQuery('#some_other_input_element').focus();
        inBlur = false;
        }
    });

, , ( jQuery ), -.

+2

$(this).focus();

-?

+1

I think the best way to prevent SQL Injection without overwriting legacy code to use parameters ( this question is now closed) would be to double all the quotes and backslash (replace 'with ''and \with \\).

Please note that I am not an expert on SQL syntax, so I cannot guarantee that this will be impervious.

0
source

Source: https://habr.com/ru/post/1719979/


All Articles