You can add the regex to the form field configuration, you don't need JS. The / and /ig prefix/suffix in your example isn't part of regex it's sed replacement commands. Remove those or use the one in your pattern field you used in JS.
If you do use JS do not modify the JSP, instead use the setting -> Settings ⇨ User Interface ⇨ Look & Feel ⇨ Embedded JavaScript, to add your JS so it will survive updates.
Adding the regex to the configuration allows server side validation which is much more secure. The client side JS can be bypassed, but it can give nicer error handling. It's entirely appropriate to do both.