Reputation: 635
I work on an html form, which I need checked with javascript regex but it is only working if I put in static text. I need the html form text(input data) to be checked against the regex.
I have searched for this around, but i can only find people showing examples with static text.
Fruther explanation: I don't need help for understanding the regular expressions. I need to understand how to pass the data, which the user inputs - into the check against the regular expression.
<script>
function fn() {
var x=document.getElementById("fname");
xv=x.value.toUpperCase();
var re = new RegExp("s", "g"); //Here is the expression i am searching for - This i do understand//
var result = re.test( ?? ); //Here should go the user input from ((("fname" - var x)))
if (result == true) {
var result = $("#result").empty();
$.post('../search.php',{xv : xv},
function(data){
result.append(data);
}
if (result == false) {
var result = $("#result").empty();
result.append("try again");
}
}
</script>
Upvotes: 0
Views: 266
Reputation: 1199
Do you mean:
var re = new RegExp("s", "g");
**var result = re.test(xv);**
if (result == true) {
}
if (result == false) {
}
Upvotes: 1