how to remove prefix and suffix from string in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To remove prefix and suffix from string in javascript, use replace() method it will return a string without your prefix and suffix but it will work only when you know the prefix and suffix, suppose if you don’t know the coming prefix and suffix then you have to put some separator at the time of creating your string like “prefix###yourstring###suffix”. Let’s see a short example of javascript removing prefixes and suffixes from string in javascript....

October 5, 2022 · 2 min · Infinitbility

how to remove  from string in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To remove  from string in javascript, use replace("Â", "") it will return a string without  character and we will also see how to replace "Â" this character with another. Let’s see a short example of javascript remove  from a string in javascript. const string = " is also a"; console.log(string.replace("Â", "")) Today, I’m going to show you How do I remove or replace  from a string in javascript, as above mentioned, I’m going to use the above-mentioned replace() method....

October 4, 2022 · 1 min · Infinitbility

Get distinct values from comma separated string javascript

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get distinct values from comma separated string in javascript, use split(",") with ...new Set() spread operator it will return array of unique values then use join() method it will return distinct values from comma separated string. Let’s see a short example of javascript remove duplicate values from comma-separated strings. const string = "infinitbility,aguidehub,sortoutcode,aguidehub,sortoutcode,infinitbility,sortoutcode"; const strArr = string.split(","); const uniqueArray = [...new Set(strArr)]; console....

October 3, 2022 · 2 min · Infinitbility

how to split string first 4 characters in javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To split first 4 characters of string in javascript, use substring(0, 4) it will return first 4 characters of string and if want another part of the string use substring(4, string.length) and it will return the else part of string. Let’s see short example of javascript get the first 4 characters of the string. const string = "0001infinitbility"; const first4Char = string.substring(0, 4); console....

October 2, 2022 · 1 min · Infinitbility

how to get size of json object in bytes javascript?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To get size of json object in bytes, use new TextEncoder().encode(JSON.stringify(obj)).length it will return size in bytes and if you want in kilobyte devide by 1024. Let’s see short example of javascript get size of json object in bytes. const obj = { id: 1, name: "infinitbility", } const size = new TextEncoder().encode(JSON.stringify(obj)).length Today, I’m going to show you How do I get size of json object in bytes in javascript, as above mentioned, I’m going to use the above-mentioned regex with TextEncoder() and JSON....

October 1, 2022 · 2 min · Infinitbility

javascript regex for email

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate email string using regex, use /^(([^<>()[\]\\.,;:\[email protected]"]+(\.[^<>()[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ it will handle date. This regex will validate string date should passing it to the Date constructor returns a valid Date object. Let’s see short example of javascript regex for validate email. const regex = /^(([^<>()[\]\\.,;:\[email protected]"]+(\.[^<>()[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; console.log(regex.test("[email protected]")) Today, I’m going to show you How do I check value contain valid date in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method....

September 28, 2022 · 2 min · Infinitbility

javascript regex for file extension

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate file extension string using regex, use /\.[0-9a-z]+$/i it will handle all type file extension. Let’s see short example of javascript regex for validate file extension. const regex = /\.[0-9a-z]+$/i; console.log(regex.test("infinitbility.exe")) Today, I’m going to show you How do I check value contain valid date in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you check valid file extension format in javascript using regex?...

September 28, 2022 · 2 min · Infinitbility

javascript regex for validate date

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate date string using regex, use /^\d{2}[\/|\-]\d{2}[\/|\-]\d{4}$/ it will handle date. This regex will validate string date should passing it to the Date constructor returns a valid Date object. Let’s see short example of javascript regex for validate date. const regex = /^\d{2}[\/|\-]\d{2}[\/|\-]\d{4}$/; console.log(regex.test("09/30/2022")) Today, I’m going to show you How do I check value contain valid date in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method....

September 28, 2022 · 2 min · Infinitbility

javascript regex for domain name

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate domain name string using regex, use /[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+/ it will handle domain name. Let’s see short example of javascript regex for domain name. const regex = /[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+/; console.log(regex.test("infinitbility.com")) Today, I’m going to show you How do I check value contain domain name in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you check domain name in javascript using regex?...

September 27, 2022 · 2 min · Infinitbility

javascript regex for hex color

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate hex color string using regex, use /^#(?:[0-9a-f]{3}){1,2}$/i it will handle hex color. Let’s see short example of javascript regex for hex color. const regex = /^#(?:[0-9a-f]{3}){1,2}$/i; console.log(regex.test("#123abc")) Today, I’m going to show you How do I check value contain hex color in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you check hex color in javascript using regex?...

September 26, 2022 · 2 min · Infinitbility

javascript regex for canadian postal code

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate canadian postal code string using regex, use /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i it will handle canadian postal code. Let’s see short example of javascript regex for canadian postal code. const regex = /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i; console.log(regex.test("h2t-1b8")) Today, I’m going to show you How do I check value contain canadian postal code in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method....

September 25, 2022 · 2 min · Infinitbility

javascript regex for comma separated numbers

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate comma separated numbers string using regex, use /^[0-9]+(,[0-9]+)*$/ it will handle comma separated numbers. Let’s see short example of javascript regex for comma separated numbers. const regex = /^[0-9]+(,[0-9]+)*$/; console.log(regex.test("1,284,473")) Today, I’m going to show you How do I check value contain comma separated numbers in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you check comma separated numbers in javascript using regex?...

September 24, 2022 · 2 min · Infinitbility

javascript regex for absolute url

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate absolute url string using regex, use /^(?:[a-z+]+:)?/// it will handle absolute url. Let’s see short example of javascript regex for absolute url. const regex = new RegExp('^(?:[a-z+]+:)?//'); console.log(regex.test("hello")) Today, I’m going to show you How do I check value contain absolute url in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you check absolute url in javascript using regex?...

September 23, 2022 · 1 min · Infinitbility

javascript regex for alphabets only

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate alphabets only string using regex, use /^[a-zA-Z]+$/ it will handle all alphabates only. Let’s see short example of javascript regex for alphabets only. const regex = /^[a-zA-Z]+$/; console.log(regex.test("hello")) Today, I’m going to show you How do I check value contain only alphabets in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you allow only alphabets in javascript using regex?...

September 22, 2022 · 2 min · Infinitbility

javascript regex for alphabets and space

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate alphabets and space string using regex, use /^[a-zA-Z]+(\s[a-zA-Z]+)?$/ it will handle all alphabates and space. Let’s see short example of javascript regex for alphabets and space. const regex = /^[a-zA-Z]+(\s[a-zA-Z]+)?$/; console.log(regex.test("hello ")) Today, I’m going to show you How do I check value contain only alphabets and space character in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method....

September 21, 2022 · 2 min · Infinitbility

javascript regex for alphanumeric

Hi Friends 👋, Welcome To Infinitbility! ❤️ To validate alphanumeric string using regex, use /^[a-z0-9]+$/i it will handle all alphabates and numbers. Let’s see short example of javascript regex for alphanumeric. const regex = /^[a-z0-9]+$/i; console.log(regex.test("hello8943")) Today, I’m going to show you How do I check value contain only alphanumeric character in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you allow only alphanumeric character in javascript using regex?...

September 20, 2022 · 2 min · Infinitbility

how to allow only alphanumeric and hyphen in javascript using regex?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To allow only alphanumeric and hyphen, use this regex /^[a-z\d\-\s]+$/i it will return true if value contain only alphanumeric and hyphen. Let’s see short example of javascript regex allow alphanumeric and hyphen. const regex = /^[a-z\d\-\s]+$/i; console.log(regex.test("hello-8943")) Today, I’m going to show you How do I check value contain only alphanumeric and hyphen in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method....

September 19, 2022 · 2 min · Infinitbility

how to allow special characters in javascript using regex?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To allow special characters, use this regex /^[[email protected]#\$%\^\&*\)\(+=._-]+$/g it will return true even if value contain special characters. Let’s see short example to use regex in javascript const regex = /^[0-9]*\.?[0-9]*$/; console.log(regex.test(90.03)) Today, I’m going to show you How do I check value contain special characters in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you allow special characters in javascript using regex?...

September 18, 2022 · 2 min · Infinitbility

how to accept only numbers in javascript using regex?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To accept only numbers, use this regex ^[0-9]*$ it will return true if value contain only numbers. Let’s see short example to use regex in javascript const regex = /^[0-9]*$/; console.log(regex.test(90)) Today, I’m going to show you How do I check value contain only numbers and dot in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method. Let’s start today’s tutorial how do you accept only numbers in javascript using regex?...

September 17, 2022 · 1 min · Infinitbility

how to allow space between words in javascript using regex?

Hi Friends 👋, Welcome To Infinitbility! ❤️ To allow space between words, use this regex /^\w+( \w+)*$/ it will return true if value contain space between words and false if space have in the left or right side and it’s also return false double space between words. Let’s see short example to use regex in javascript const regex = /^\w+( \w+)*$/; console.log(regex.test("hello 8943")) Today, I’m going to show you How do I check value contain space between words in javascript, as above mentioned, I’m going to use the above-mentioned regex with test() method....

September 16, 2022 · 2 min · Infinitbility