2

I'm quite new to javascript and I can't find a single guide how to check string format (except whole code how to check e-mail etc).

So I need to check if my variable is in this format - applicationcode0001. The text is not going to change - so something like this - variable=="applicationcode"+[number]+[number]+[number]+[number]

If you can provide me some link how to check string variables like that, I will be super happy.

Thanks, MJ

Michal Janošec
  • 71
  • 1
  • 10

2 Answers2

2

var myRe = /^applicationcode\d{4}$/;
console.log(myRe.test('applicationcode0001'));
Kos
  • 4,890
  • 9
  • 38
  • 42
Mati Tucci
  • 2,826
  • 5
  • 28
  • 40
1

    var regex = RegExp('applicationcode[0-9]{4}','g');
    var str1 = 'applicationcode1234';

    console.log(regex.test(str1));
    // expected output: true
    //
Biswadev
  • 1,456
  • 11
  • 24