Regular expression keeps failing

My regular expression keeps failing and not sure what i’m doing wrong, code below:

var get_memberCity = "test";

	let cityRGEX = /^([a-zA-Z]{0, 5})$/;
	let cityResult = cityRGEX.test(get_memberCity);
	/****************************************************************************/
	if(get_memberCity != "" ) {
		console.log("RegExp test =>: "+ cityResult + "  --- cityREGX -->: "+cityRGEX);			
		if(cityResult) { 
			console.log("Valid");
		} else {
			console.log("Failed");
			return false;
		}
}

Well to start with, you have a syntax error because val is not a valid keyword.

If it’s in regard to the repetition count from 0 to 5, you have a space in there that shouldn’t be.

HI Paul,
made correction and removed the space and it worked… thanks…

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.