RegEx in javascript. Allow only letters, comma and punctuation
javascript, regex
Solution
You might need to escape the "." as that is a special character in regex.
/^[A-Za-z0-9,\. ]{3,50}$/;
Actually probably not. Try using http://www.regextester.com/ - I was able to get it to work anyway. Can you show us the full code for how you're implementing this?
Problem
I try to make a RegEx for validating a form in javascript. The RegEx should only allow letters comma and punctuation. For instance I have this string: ``` Hi, this is a test of RegEx. Does it work ``` I've tried the following ``` /^[A-Za-z0-9,. ]{3,50}$/; ``` But it doesn't seems to work. Solutions? Thanks! EDIT: This is my code: ``` <script type="text/javascript"> var RE_SSN = /^[A-Za-z0-9,. ]{3,50}$/; function checkSsn(ssn){ if (RE_SSN.test(ssn)) { alert("OK"); javascript:addAppointment(document.forms[0]) } else { alert("NO!"); } } </script> <div id="r"> <label for="receipt">Receipt</label><input type="checkbox" name="receipt" value="1"/> </div> <input type="button" value="Post it" onclick="checkSsn(this.form.content.value);"/> ```