Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
if i run, validation just can be work only on symbol "/", if I input the other symbol except / didnt working. I'm not use regex. loop like stop work.

JavaScript
if(nama!==""){
var i;
var list = new Array ("/","!", "@", "#","$","%","%","^","&","*",
                      "(",")","_","+","=","-","`","~",";","<",
                      ">",".","?","[","]","{","}",",");

var llength = list.length;
for(i=0; i<llength;>{
    if(nama.match(list[i]))
    {
        alert("Full Name must not contain any number and symbol");
        return false;
    }

}
}
Posted
Updated 9-Dec-15 7:42am
v2
Comments
Sergey Alexandrovich Kryukov 9-Dec-15 14:32pm    
This is not a correct question. You need to formally define the rule. In particular, there are a lot more "symbols" (what is it, precisely? :-) then what you listed.
—SA

Why not a simple Regex?
Try this-
JavaScript
if(nama!==""){
  var regex= /^[a-zA-Z]+$/;  
  if(! nama.value.match(regex)){  
     alert("Full Name must not contain any number and symbol");
     return false;
  }
}

Isn't that very simple !

Note:
1. You are saying you are not using regex but, .match() actually match against a regular expression.
Quote:
The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.

Reference: JavaScript String match() Method[^]
2. You are saying you want to allow alphanumeric but from your alert message it looks like you want to allow only the characters.

Hope, it helps :)
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 9-Dec-15 14:30pm    
I voted 4. The problem your code has is not entirely your fault — the inquirer did not correctly formulate the validation rule.
It's amazing how many our inquirers try Regex processing where it is totally unsuitable, even insist on using (misusing) it, and yet some deny using Regext when it's the easiest way.

So, the problem is, the inquirer's "Full Name must not contain any number and symbol" does not imply that the valid characters are letters. But even it they were letters, you listed only a-z and A-Z, but there are a lot more letters. If allowing only the letters, the right implementation should be, again, not Regex, but based on the method char.IsLetter.

—SA
Suvendu Shekhar Giri 9-Dec-15 14:41pm    
(bow) Agree. Can you please post the same as a solution so that OP and others can be benefited.
Sergey Alexandrovich Kryukov 9-Dec-15 14:56pm    
I would prefer to wait until the inquirer clarifies the validation criteria.
—SA
Please try the below...


C#
var a = '09azAZ!'
var t = '';

alert(a);

for(i=0;i<a.length;i++)
{
	t = a.charCodeAt(i);
		//alert(t);
	if((t<48) || ((t>57) && (t<65)) || ((t>90) && (t<97)) || (t>122))
	{
		alert('Not alphanumeric: ' + a.charAt(i));
		//return;
	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900