Jquery regex match code does match good and not good

Jquery regex match code does match good and not good

Hi

I use a code to check input value with regex.
When I "blur" input it checks and tell me its good when passed.
When I click into same input again and "blur" away it checks again but now tells its not ok what Im doing wrong?

My Code is:

  1. <input type="text" id="name" name="name" placeholder="name" /><a>??</a><br />

  2. <script>
  3. $(document).ready(function (){
  4. $("input").blur(function () { checkvalue(this) })

  5. function checkvalue(i) {
  6. if ($(i).val() != ("")) {
  7. if (eval($(i).attr("name") + "regex").test($(i).val())) {
  8. errorlevel = errorlevel - 1
  9. $(i).next("a").html("OK").css("color","#007700")
  10. } else {
  11. errorlevel = 4
  12. $(i).next("a").html("XX").css("color","#ff0000")
  13. }
  14. } else {
  15. errorlevel = 4
  16. $(i).next("a").html("XX").css("color","#ff0000")
  17. }
  18. }

  19. })
  20. </script>