I'm trying to use jQuery to alter the textbox color, when a regex validator fails.
Here is a function I found online, but I don't know how to alter it to use regex.
<script type="text/javascript">
function ValidateTextBox(source, args)
{
var is_valid = $("#TextBox1").val() != "";
$("#TextBox1").css("background-color", is_valid ? "white" : "red");
args.IsValid = is_valid;
}
</script>
Also, I don't understand what the use of
args.IsValid = is_valid;
Is in the function.
Here is what I am trying now:
<script type="text/javascript">
function ValidateTextBox(source, args) {
var is_valid = false;
//Regex goes here
var regex = [A-Za-z];
if (regex.test($('#TextBox1').val())) {
//If input was correct
is_valid = true;
}
else {
//If input is not correct
$("#TextBox1").css("background-color" : "red");
}
args.IsValid = is_valid; //Returns validity state
}
</script>