Home > Blockchain >  Need regex for project name with the following conditions
Need regex for project name with the following conditions

Time:07-11

Need regex for the "Project name" with following condition. Expected Result: Take alphabetical, alpha numeric, alpha numeric symbolic Actual Result:

1.    Take alpha – Pass
2.    Take Numeric – Pass
3.    Take Alpha numeric – Pass
4.    Take alpha numeric special characters - Pass
5.    If Only special characters – Fail

that is, Everything is allowed but if it is just special characters and no text than it's a problem. **Example:

  • zjna5726$7&^#bsg //allowed
  • %&*% // just special characters not allowed
  • I tried /^[ A-Za-z0-9_@./#& -]*$/ but did not help
  • ^([\w \d ] )((-)([\w \d ] ))* //did not help it is only excepting one character in between only.

CodePudding user response:

Is not just simply to check that this has a match ? /\w /

if (teststring.match(/\w /) != null) ..

CodePudding user response:

Why don't you just check if there is included Numeric or Alpha?

if("string".match(/A-Za-z0-9/)) // do something
else // do something else
  • Related