How to validate an Input Field contain some special charcters or not?

Hi there

I have a field like Input text I want that that field conatin or not these charcters $,#,*,
So far there is some problem in my jsfiddle.net account.So I am not posting any jsfiddle.net

I want that field should validate using pure JS not any JQuery and other libraray

How to do this?

hey @vngx

See if a js code something like this might help for pure js validation.

<scrindent preformatted text by 4 spacesipt type=“text/javascript”>
function validate()
{
alert(“Please Enter required fields”);
var ctr = 0;
debugger;
var name=document.getElementById(‘username’).value;
if(name==“”)
{
alert(“For completing the form, it requires you to input a Name”);
document.getElementById(‘username’).style.border=“1px solid red”;
document.getElementById(“username”).innerHTML=(“Enter the Name”);
return false;
}
if(document.getElementById(‘Address’).value==“”)
{
alert(“For completing the form, it requires you to input a Address”);
document.getElementById(‘Address’).style.border=“1px solid red”;
document.getElementById(“Address”).innerHTML=(“Enter the Address”);
return false;
}

@skymodigiworld

read my question carefully

@vngx
may i know what wrong did i interpret :blush:

Suppose I want that Input field should contain “$”,“#”,“@” any of them along with other charcters or sysmbols

What will be pattern for this?

@vngx

For checking Regular expressions for special charterers

var ck_username = /[1]{3,20}$/;
Supports alphabets and numbers no special characters except underscore(‘_’) min 3 and max 20 characters.

var ck_password = /[2]{6,20}$/;
Supports special characters and here min length 6 max 20 charters.

Check out these two links they might help you

I hope this helps


  1. A-Za-z0-9_ ↩︎

  2. A-Za-z0-9!@#$%^&*()_ ↩︎

@skymodigiworld
Thanks for your effort
but You do not get still my point

I am not looking for supporting charcters
I want whethar a particular field contain some symbol in it or not like suppose “123456&&” I want to check on this that it contains some symbols in it or not

Then you’ll be after something like this.

var symbols = /[!@#$%^&*()_]/,
    hasSymbol = symbols.test(someText);

Thanks @Paul

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