Determining the operator from a string using javascript -
i need help.
i need come javascript function check string entered textbox determine sql operator
example:
var field1 = document.getelementbyid('field1').value var field2 = document.getelementbyid('field2').value var field3 = document.getelementbyid('field3').value function validate(textbox) { var operator if ('%' first character placed before , after value) { operator = } else if ('%' first character placed before value) { operator = } else if ('%' last character placed after value) { operator = } else { operator equals "=" } //default alert(operator) }
example of function in action:
validate(field1)
you can use regular expressions this. looks if string contains %
, operator like
. can this:
var operator = "="; //if string starts % or ends % //the operator "like" if(/^%/.test(str) || /%$/.test(str)) { operator = "like"; }
Comments
Post a Comment