We help IT Professionals succeed at work.
Get Started

asp.net mvc4

Moti Mashiah
Moti Mashiah asked
on
125 Views
Last Modified: 2015-03-02
Hi Guys ,

I'm working on asp.net mvc4 web application and i'm trying to restrict special character from input fields.

for example I have this textbox:

Supplier Contact:  @Html.TextBoxFor(m => m.POTitle, new { @class = "form-control", @placeholder = "Type Name Or Email" })

Open in new window


I would like the restrict like character - /^\s*[a-zA-Z0-9,\s]+\s*$/ when users type in.

I found some jquery something like that:
$(document).ready(function () {
    var charReg = /^\s*[a-zA-Z0-9,\s]+\s*$/;
    $('.keyup-char').keyup(function () {
        $('span.error-keyup-1').hide();
        var inputVal = $(this).val();

        if (!charReg.test(inputVal)) {
            $(this).parent().find(".warning").show();
        } else {
            $(this).parent().find(".warning").hide();
        }

    });
});

Open in new window


but i dont know how to use it in my case.
Comment
Watch Question
Senior Software Engineer
CERTIFIED EXPERT
Top Expert 2009
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE