In theoretical computer science and formal language theory, a regular expression (abbreviated regex or regexp) and sometimes called a rational expression is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. “find and replace”-like operations. The concept arose in the 1950s, when the American mathematician Stephen Kleene formalized the description of a regular language, and came into common use with the Unix text processing utilities ed, an editor, and grep (global regular expression print), a filter.


In practical terms, i gonna use regex to validate from, before send it to database. This is effective solution, so user that filled form will not wait if form reject submit after submit button pressed.

What kind of criteria i`ve used?

  • username must contain letter AND Number
  • email must valid
  • PIN must only number

Regex: username must contain letter AND Number

$(document).ready(function() { 
        $('.keyup-numeric').keyup(function() {
            var inputVal = $(this).val();
            var numericReg = /^(?=.*\d)(?=.*[a-zA-Z])/;
            if(!numericReg.test(inputVal)) {    
                $(this).after('<span style="color:red;" class=" error-keyup-1"><br>Harus Angka <strong>DAN</strong> Huruf </span>');

Regex: Must valid email


 $('.keyup-email').keyup(function() {
            var inputVal = $(this).val();
            var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            if(!emailReg.test(inputVal)) {  
                $(this).after('<br><span style="color:red;" class=" error-keyup-7">Invalid Email Format</span>');

Regex: PIn Must Number


$('.keyup-pin').keyup(function() {
            var inputVal = $(this).val();
            var ccReg = /\b[0-9](?!.*123456,654321).*0-9\b/;
            if(!ccReg.test(inputVal)) { 
                $(this).after('<span style="color:red;" class="  error-keyup-10">harus 6 ANGKA</span>');



Regex Tester

Android Regx Tool
RegEx Generator