Vikas Kumar Vikas Kumar - 1 year ago 81
jQuery Question

Why is this regular expression accepting special characters and numbers?

I've created a simple regular expression for email. It is:


Now the problem is that it's accepting an email like
when tested. But it shouldn't allow
I want letters only.

Secondly, please tell me about beginning (
) and end (
) symbols used in regular expression. I read about them on codeacademy but couldn't understand their purpose. Do they have something to do with my original problem?

Here's the whole jQuery:

<script type="text/javascript">
var $pat1=/[a-zA-Z0-9]{5}/;
var $pat2=/[a-z]+@{1}[a-z]{2,}/;
var $name=$("input[name='pname']").val();
var $email=$("input[name='pmail']").val();
var $pswd=$("input[name='pswd']").val();
if(($name!="" && $email!="") && $pswd!=""){

Answer Source

Try this regex


Your string must start with a-z (^) and end in a-z($)

^ and $ are for beginning and end

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download