0

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>
3
  • Is this being done in jQuery? I recognize the $() and $, but unfortunately am not very skilled in jQuery.... Commented Jan 17, 2013 at 2:59
  • do you want to test the value of xv with the regex re? Commented Jan 17, 2013 at 3:03
  • I want the user input into the regex check. Commented Jan 17, 2013 at 9:34

1 Answer 1

1

Do you mean:

    var re = new RegExp("s", "g");
  **var result = re.test(xv);**
    if (result == true) {

    }

    if (result == false) {  

    }
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, EXCEPT it is not working. I have a start text in the "result", to check if the function true / false is initiated.
OK, i see that i have spend most of yesterday looking for crazy workarounds. I have been inputting "vx", when i just needed to change "vx" -> "xv".. :-P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.