Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java GUI Discussions 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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 2nd, 2003, 02:01 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validation for special character

Hi,

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.

Thanking in Advance
Naz
Reply With Quote
  #2 (permalink)  
Old September 2nd, 2003, 04:18 AM
Authorized User
 
Join Date: Aug 2003
Location: , , Ghana.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to egolileopablo Send a message via Yahoo to egolileopablo
Default

try this and you can set the foreground too.
use
 getContentPane().setBackground(color.red)

Reply With Quote
  #3 (permalink)  
Old February 8th, 2005, 03:56 AM
Registered User
 
Join Date: Oct 2004
Location: New Delhi, Delhi, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Friends,

Here is the code to check for an alphabet,number etc.
It is tested and working code. Just use it.
Happy Programming.

Pushp.

-------

<HTML>
<HEAD>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Author" content="Pushpendra: <engineer.sw@gmail.com>">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Pushpendra:<engineer.sw@gmail.com>: Java Script Strong Password Validtions</title>

<script language="javascript">
function isStrongPassword()
{

   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");
   control.value="";
   control.focus();
   return false;
   }
   if(specialString < 1)
   {
   alert("Passwords must include at least 1 special (#,@,&,$ etc) characters");
   control.value="";
   control.focus();
   return false;
   }
   if(digitString < 1)
   {
   alert("Passwords must include at least 1 numeric characters");
   control.value="";
   control.focus();
   return false;
   }
   return;
}
</script>

</HEAD>
<BODY>

<P><h2>Registration</h2>
<form id=form1 name=form1>
<table>
<tr><td>Login:</td>
<td><INPUT id=login name=login size="20"></td>
</tr>
<tr><td>Password:</td>
<td><INPUT id=password name=password size="20"></td>
</tr>
</table>
<P><INPUT id=register type=button value=Register name=register onclick='javascript:isStrongPassword()'></P>
</form>
</BODY>
</HTML>

"Deleted code has fewer bugs."
Reply With Quote
  #4 (permalink)  
Old February 8th, 2005, 05:42 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

If you want to apply Push's example to java, look into java.util.regex.pattern class:

http://java.sun.com/j2se/1.5.0/docs/...x/Pattern.html


Hope this helps ;)
Reply With Quote
  #5 (permalink)  
Old February 9th, 2006, 11:13 AM
Registered User
 
Join Date: Feb 2006
Location: Seattle, , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This certainly keeps bad passwords out.

However, the form you attached the JavaScript to does absolutely nothing useful. Please help!

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.

Reply With Quote
  #6 (permalink)  
Old February 13th, 2006, 03:13 PM
Registered User
 
Join Date: Oct 2004
Location: New Delhi, Delhi, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi Peter,

I had created a demo form for the post. You can copy Java script function and paste it any where. Fire the function at any amy event.

In case of any problem do write to me at pushpendratiwari@gmail.com

Pushpendra



"Deleted code has fewer bugs."
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing special character data mussitsch Classic ASP Professional 4 September 5th, 2006 03:29 PM
Decimal code for a special character mcinar HTML Code Clinic 14 February 4th, 2005 01:56 PM
Special Character mg1966 Classic ASP Databases 2 December 13th, 2004 11:12 AM
XML - Special Character Formatting sean1230 XML 3 February 18th, 2004 05:17 AM
finding the string before a special character srini XSLT 2 December 16th, 2003 07:57 AM



All times are GMT -4. The time now is 08:04 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.