78130

Regex, detect no spaces in the string

This is my current regex check:

const validPassword = (password) => password.match(/^(?=.*\d)(?=.\S)(?=.*[a-zA-Z]).{6,}$/);

I have a check for at least 1 letter and 1 number and at least 6 characters long. However I also want to make sure that there are no spaces anywhere in the string.

So far I'm able to enter in 6 character strings with spaces included :(<img src=https://www.e-learn.cn/content/wangluowenzhang/"https://i.stack.imgur.com/tpPBh.png" alt="enter image description here">

Found this answer here, but for some reason in my code it's passing.

What is the regular expression for matching that contains no white space in between text?

Answer1:

It seems you need

/^(?=.*\d)(?=.*[a-zA-Z])\S{6,}$/

<strong>Details</strong>

    <li>^ - start of string</li> <li>(?=.*\d) - 1 digit (at least)</li> <li>(?=.*[a-zA-Z]) - at least 1 letter</li> <li>\S{6,} - 6 or more non-whitespace chars</li> <li>$ - end of string anchor</li> </ul>

    With a principle of contrast in mind, you may revamp the pattern into

    /^(?=\D*\d)(?=[^a-zA-Z]*[a-zA-Z])\S{6,}$/

Recommend

  • How do I recognize a line break with a switch case that evaluates a char in Java?
  • how to check the textarea content is blank using javascript?
  • Updating and removing unique join relationships in CakePHP
  • Using HTML/CSS for UI in XNA?
  • Certain Arabic text gets incorrectly shown while other Arabic text gets showed normally?
  • custom string delimiters stringtemplate-4
  • How to search a CSV file with php by checking if a date falls between 2 ranges
  • C function strchr - How to calculate the position of the character?
  • (Tcl/Expect) clear screen after exit
  • several dataProvider per one Test in TestNG
  • Scanner nextInt() and hasNextInt() problems
  • Validate jQuery plugin, field not required
  • Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)
  • jQuery: How to AJAXify WordPress Search?
  • how to set variables in a php include file?
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • Trying to get the char code of ENTER key
  • How to make JSON.NET deserialize to Microsoft Date Time?
  • Reading a file into a multidimensional array
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • Eloquent paginate function in Slim 3 project using twig
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Content-Length header not returned from Pylons response
  • Play WS (2.2.1): post/put large request
  • How to access EntityManager inside Entity class in EJB3
  • Is there a javascript serializer for JSON.Net?
  • Where to put my custom functions in Wordpress?
  • vba code to select only visible cells in specific column except heading
  • When should I choose bucket sort over other sorting algorithms?
  • Jquery - Jquery Wysiwyg return html as a string
  • AT Commands to Send SMS not working in Windows 8.1
  • Arrays break string types in Julia
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Buffer size for converting unsigned long to string
  • WPF Applying a trigger on binding failure
  • -fvisibility=hidden not passed by compiler for Debug builds
  • Java static initializers and reflection
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++
  • Binding checkboxes to object values in AngularJs