How to Detect Symbols & spaces With RegEx!

Regex Is Awesome, I am learning regex.

A good Example is to make a simple symbol & space detector with RegEx!
You can use RegExp in javascript

Use \W in RegExp to detect symbols & spaces.
& use .match() in Javascript to search…


This content originally appeared on DEV Community and was authored by MAFEE7

Regex Is Awesome, I am learning regex.

A good Example is to make a simple symbol & space detector with RegEx!
You can use RegExp in javascript

Use \W in RegExp to detect symbols & spaces.
& use .match() in Javascript to search for the symbols.

A RegExp is can be written as a pattern: /\W/g

Example In Javascript
   var text = prompt("Enter a Name (symbols & spaces not allowed!)"); // Take user Input.
   if(text.match(/\W/g) == null){ // Check if there are spaces, symbols.
     alert("Good Name!!"); // If valid.
   }else{
     alert("Bad Name!! Remove Those Spaces And Symbols!"); // If Invalid
   }


This content originally appeared on DEV Community and was authored by MAFEE7


Print Share Comment Cite Upload Translate Updates
APA

MAFEE7 | Sciencx (2021-05-13T07:46:20+00:00) How to Detect Symbols & spaces With RegEx!. Retrieved from https://www.scien.cx/2021/05/13/how-to-detect-symbols-spaces-with-regex/

MLA
" » How to Detect Symbols & spaces With RegEx!." MAFEE7 | Sciencx - Thursday May 13, 2021, https://www.scien.cx/2021/05/13/how-to-detect-symbols-spaces-with-regex/
HARVARD
MAFEE7 | Sciencx Thursday May 13, 2021 » How to Detect Symbols & spaces With RegEx!., viewed ,<https://www.scien.cx/2021/05/13/how-to-detect-symbols-spaces-with-regex/>
VANCOUVER
MAFEE7 | Sciencx - » How to Detect Symbols & spaces With RegEx!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/13/how-to-detect-symbols-spaces-with-regex/
CHICAGO
" » How to Detect Symbols & spaces With RegEx!." MAFEE7 | Sciencx - Accessed . https://www.scien.cx/2021/05/13/how-to-detect-symbols-spaces-with-regex/
IEEE
" » How to Detect Symbols & spaces With RegEx!." MAFEE7 | Sciencx [Online]. Available: https://www.scien.cx/2021/05/13/how-to-detect-symbols-spaces-with-regex/. [Accessed: ]
rf:citation
» How to Detect Symbols & spaces With RegEx! | MAFEE7 | Sciencx | https://www.scien.cx/2021/05/13/how-to-detect-symbols-spaces-with-regex/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.