Simple Javascript Regex

some overview about what JS offer in terms of regex
http://www.javascriptkit.com/javatutors/redev3.shtml
more info about the use of RegExp object
\http://www.w3schools.com/jsref/jsref_obj_regexp.asp
and a simple example i found somewhere for PW check:

$(function () {
   $('#txtNewPW').keyup(function () {
      $('div.errorRegexPw').hide();
      var inputVal = $(this).val();
      var numericReg = /<%= PWRegex %>/;
      if (!numericReg.test(inputVal)) {
          $(this).after('<div class="errorRegexPw">Not A Valid Password.</div>');
      }
   });
});

thing is that to init the RegExp obj u just need to do var regex = /pattern/; with the 2 '/'.
now all u need to do is regex.test(string_to_test) and get true or false like:

var regex = /ariel/;
var t = regex.test("ariel");
var f = regex.test("arik");
here t will be true and f will be false

Comments

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

Asp.Net Ending Response options, Response.End() vs CompleteRequest()