Skip to main content

Posts

Showing posts with the label regex

Using Regular Expression / Regex In Javascript!

Writing a simple function to extract matched strings using Regex in Javascript Today i want to show how to extract string data using Regular Expression in Javascript. A regular expression is an object that describes a pattern of characters. Syntax for javascript : / pattern / modifiers ; First we can create a simple function that will process the string extraction. example of string input will be something like this <p>This is just a simple example input string</p> (     [message] => "Hello",     [desc] => "its a handshake hello!" ) <p>The purpose is to extract message and desc pattern matching</p> Simple function that will process the string extraction function extract(stringInput) { var regexp = /\[(message|desc)\](.*)/gm; var arr = []; while (result = regexp.exec(stringInput)) { arr.push(result[0]); } return arr; } The ' extract ' function will look for a pattern on anything that has opening bracket with the matching ...

Populate Whatsapp Link Based on Seller Phone Number WCFM

Hi all, Image from Pexels Today I'm going to share, how to populate WhatsApp link based on the seller number. My example today is based on Malaysia's phone number. The registration input doesn't have an input validator for the phone number, however, these are the most common number registered by users. 1) starting with 6 at front 2) starting with +6 at front 3) normal number without country code eg : 014xxxxxx Full code on how to populate whatsapp link for seller number basically, I introduced a simple pattern that has 2 groups. "#(^[6]\w*$)|(^[+][6]\w*$)#"; The patterns must have a delimeter added for PHP, in my case i use a `#`. You can use other delimiter that supported by PHP . The first pattern (^[6]\w*$) Checks whether the seller phone number starts with number 6 and followed with other characters. If it is matched, do nothing as the format is already correct. The second pattern (^[+][6]\w*$) Checks whether the seller phone ...