Java GUIDiscussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I need to validate a string for numeric and special character such that the string should contain minimum of 1 numeric digit and 1 special character.
I tried checking it with all special characters one by one but i feel its not a very good idea, a better thing would be to check each character first for an alphabet(A-z or a-z) else for a number else it is a special chacter.
But I dont know how to use this.
I checked out on the sites for a function containsonly but I am not very sure of how to use it.
Please tell me how do i check for an alphabet,number.
var control = document.form1.password;
var myString= control.value;
var Stringlen = myString.length;
var ValidateDigits = /[^0-9]/g;
var ValidateSpChar = /[a-zA-Z0-9]/g;
var ValidateChar = /[^a-zA-Z]/g;
var digitString = myString.replace(ValidateDigits , "");
var specialString = myString.replace(ValidateSpChar, "");
var charString = myString.replace(ValidateChar, "");
if(Stringlen < 8)
alert("Passwords must be at least 8 characters");
if(specialString < 1)
alert("Passwords must include at least 1 special (#,@,&,$ etc) characters");
if(digitString < 1)
alert("Passwords must include at least 1 numeric characters");
And after adding "action=index.html" to the form, it still does nothing. Cleaning out the non-contributing table and font coding still gets me no action. I think I will stick to a simple validation script that applies only one regular expression such as /[a-zA-Z0-9]/g; and then allow the login to actually log someone in.