Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-14-2008, 01:14 PM
Member
 
Join Date: Apr 2008
Posts: 2
tanalyw is on a distinguished road
How do check I allow user to enter only alpha numeric and -?
Hi another question

I need to do a prompt on console.
However, the prompt only accepts alpha numerical values and dash (-)
How do i go about it.

I only manange to check if the input user entered is alpha-numeric using this method,

boolean true = username.matches("\\p{Alnum}+");

how do i prevent user from entering funny characters like )(*&^%$#@! except for - ? thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-15-2008, 01:42 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
I think this is what you're looking for.

Code:
if (!test.matches("[\\p{Alnum}[\\-]]*")) { //error } else { //your ok }

Last edited by Chris.Brown.SPE : 04-15-2008 at 01:46 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 01:18 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 518
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Try this algorithm, ( in a GUI "textfield" )

Before the user inputs, save the current value of textfield on a variable.
in every input, check the last character for decimal and dash
if satisfied, allow and replace the saved value to this new one.
else, remove the text, and replace it with the value that was stored.

kind regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
get numeric value from a text field Lehane_9 New To Java 2 06-14-2008 04:19 AM
Applet - enter URL and view the page Java Tip Java Tips 0 03-10-2008 03:38 PM
Allowing only numeric values in a TextField Java Tip Java Tips 0 03-01-2008 11:08 PM
enter data from an optic device bbq Advanced Java 2 07-04-2007 09:02 AM
Javascript and enter button Eric Advanced Java 1 06-11-2007 10:39 PM


All times are GMT +3. The time now is 06:47 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org