1

I hope you can help me to figure this out. I need to be able to build a regular expression in js that allows letters, numbers and symbols such as plus (+) just after the ?s=...

right now I'm trying something like this

var regexp = '^[a-z0-9]';
if (url == 'https://digitalswitch.cl/rileditores/?s=' + regexp){
   //do something
}else{
   //do something else
}
empiric
  • 7,825
  • 7
  • 37
  • 48
calljhon
  • 72
  • 2
  • 9
  • see [`.match()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) and fix your regex, it's not valid as it stand right now. – empiric Jan 25 '18 at 12:53
  • symbols ,,,you should list how many symbols you could accept – xianshenglu Jan 25 '18 at 12:54
  • Possible duplicate of [Regex for allowing alphanumeric,-,\_ and space](https://stackoverflow.com/questions/13283470/regex-for-allowing-alphanumeric-and-space) – Ayaz Ali Shah Jan 25 '18 at 12:54

1 Answers1

0

var str     = "https://digitalswitch.cl/rileditores/?s=sample";
var matches = str.match(/\?s=([^&]*)/);
if(matches){
   alert('matched');
}else{
   alert('not matched');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

The following example will search "?s" is available at the link or not. If yes alert "matched", else "not matched".

Hope this will helps you.

For more example,

Sunil Dora
  • 1,407
  • 1
  • 13
  • 26