Input validation with regex alphanumeric and allow only some special characters [duplicate] - javascript

This question already has answers here:
How to escape backslash in JavaScript?
(2 answers)
Backslashes - Regular Expression - Javascript
(2 answers)
Can't escape the backslash with regex?
(7 answers)
Closed 4 years ago.
I want a custom validation for an input box and tried with this. /^[a-zA-Z0-9\,/.-\s]*$/ It will allow only the following special characters , . / - and blank space. I want to add one more special character and that is \ How can I achieve this.

Related

need some changes in spliting - Javascript [duplicate]

This question already has answers here:
Limiting the times that .split() splits, rather than truncating the resulting array
(8 answers)
javascript split string by space, but ignore space in quotes (notice not to split by the colon too)
(3 answers)
Split a string by whitespace, keeping quoted segments, allowing escaped quotes
(4 answers)
Regex for splitting a string using space when not surrounded by single or double quotes
(16 answers)
Javascript split by spaces but not those in quotes
(3 answers)
Closed 8 days ago.
"/ban Hitesh27 "Disrespect so banned".split(" ")
exepected was [ "/ban", "Hitesh27", "Disrespect so banned"]
Result was [ "/ban", "Hitesh27", "Disrespect", "so", "banned"]
i see why the result was like that but i don't know how to fix it yet

Handling special characters in Java script to enclose them in Square Brackets? [duplicate]

This question already has answers here:
Wrap Numbers in Brackets using javascript .replace regex
(1 answer)
Check for special characters in string
(12 answers)
Closed 2 years ago.
I am trying to write a Java Script function that should enclose all the special characters in the given String in a bracket like following -
Input ===> Output
123##$, ====> 123[#][#][$][,]
Changing All the special characters to certain String [ _ in this case] is easy -
string = string.replace(/[^a-zA-Z0-9]/g,'_');

JavaScript get text between round brackets ignoring inside brakets [duplicate]

This question already has answers here:
Regular expression to match balanced parentheses
(21 answers)
How can I match nested brackets using regex?
(4 answers)
Closed 4 years ago.
I want to get the text inside this bracket using regexp
var str = "func(arg(), arg)()";
str.match(/regex/)[0]; // Results "arg(), arg"

Regex to get string between two specific tags [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
What special characters must be escaped in regular expressions?
(13 answers)
Closed 4 years ago.
I have a string like:
[device]Some device[/device]
I am trying to write regex that will return only "Some device".
/[device](.*?)[/device]/i.exec(str) // doesn't work
/[device](.*)[\/device]/g.exec(text) // doesn't work
I am not sure how to extract it?
I already tried solution from Regular Expression to get a string between two strings in Javascript and it doesn't work for string like [][/]
[device]Some device[/device]
return
evice]Some device[/device] and all other strings.

REGEX javascript - find two chars set [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
i've to find the sequence of chars ,. inside a json file for example: ":0,.0}},{", so what is the best fitted regex string for it?
i tried /(,.){1,}/g but it doesn't work well.
It's because . is a special character.
const r = /(?:,\.)+/g
console.log('abc,.,.,.def'.match(r)) //[",.,.,."]
you need to escape the .:
/,\./g

Categories

Resources