regex for allowing only certain special characters and also including the alphanumerical characters

Tinus Jackson

I'm struggling with REGEX and require it for a program.

The input require only alphanumerical keys and also (allow only comma,:,space,/,- in special chars)

I have tried = (^[a-zA-Z0-9,:\S/-]*$) As far as i understand and please correct me if I'm wrong. a-zA-Z0-9 - The alphanumerical keys. ,: - Comma and colon \S - Space / - I'm not sure how to represent a forward slash thus i escaped it - - Dash also not sure if it is needed to escape it.

Would be appreciated if this can be corrected and also a explanation of each part.

Thanks in advance.

Stanislav

You can replace a-zA-Z0-9 with just \\w which is short for [a-zA-Z_0-9]. Furthermore, \\S is any character, but not a whitespace, you should use a \\s instead. You don't need to escape /, and even - if it's the first one or the last one, because if it's placed between two characters it could be interpreted as range and you'll have to escape it. So, you can make your regex like ^([\w,:\s/-]*)$

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Regex not allowing certain special characters

Jquery alphanumerical (+ special characters) regex

regex for not allowing <> special characters

Only allowing certain characters

Javascript - Regex for allowing only selected special characters only

regex for allowing alphanumeric, special characters and not ending with @ or _ or

Regex to allow only certain special characters and restrict underscore

Regex for including alphanumeric and special characters but not special characters on their own

Regular Expression for not allowing two consecutive special characters and also not in beginning and end

Regex boundary to also exclude special characters

regex maximum length not including special characters

Regex to detect string including special characters

RegEx for Including special character and characters inside a [ ]

Regex to permit only certain characters

Regex - Validate that the local part of the email is not ending with a dot while only allowing certain characters without using a lookbehind

Regex allowing and disallowing characters

How to replace only certain special characters in PHP?

Allowing special characters and code injection

How to match a string with at least one letter, allowing only certain characters?

Regex to accept special characters only with alpha numeric

Ignore only one special characters in regex

How to limit the number of characters while also allowing only a subset of characters in a TextField?

Regex Pattern for not allowing slash on beginning and ending and not allowing special characters except slash, underscore, space

Regex in asp.net for allowing only characters with single space?

I want a regex that will select all characters including special characters, except the Last 4 Characters. Vanilla JS

Regex for Any English ASCII Character Including Special Characters

using regex to match a string including with numbers and special characters

Java String Split on any character (including regex special characters)

how to match a text including special characters in using regex in oracle

TOP Ranking

HotTag

Archive