I need to verify if a string is not starting and ending with ";" and if there is only one occurence of ";" if this special char is inside the string(not at the start , not at the end) . I must use a regex in these case i think
For example :
var regex =new RegExp("^\w+;\w+", "g"); ;
var test = ';azerty1;azerty2;azerty3'; //invalid
var test2 = 'azerty1;azerty2;azerty3'; //valid
var test3 = 'azerty1;azerty2;azerty3;'; //invalid
var test4 = 'azerty1;azerty2;;azerty3'; //invalid
var test5 = 'azerty1;azerty2;azerty3;azerty4'; //valid
var test6 = ';;azerty1;azerty2;azerty3;azerty4'; //invalid
var test7 = 'azerty1;azerty2;azerty3;azerty4;;'; //invalid
var test8 = 'azerty1azerty2azerty3azerty4'; //valid
var array = [test , test2 ,test3 ,test4 ,test5 ,test6 ,test7 , test8];
for(var i= 0; i < array.length; i++)
{
if(regex.test(array[i]))
{
alert("TRUE");
}
else
{
alert("FALSE");
}
}
Any help would be appreciated Thank you very much