Results 1 to 3 of 3
- 04-14-2008, 12:14 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 4
- Rep Power
- 0
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
- 04-15-2008, 12:42 PM #2
I think this is what you're looking for.
Java Code:if (!test.matches("[\\p{Alnum}[\\-]]*")) { //error } else { //your ok }
Last edited by Chris.Brown.SPE; 04-15-2008 at 12:46 PM.
- 04-16-2008, 12:18 PM #3
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
Similar Threads
-
get numeric value from a text field
By Lehane_9 in forum New To JavaReplies: 2Last Post: 06-14-2008, 03:19 AM -
Applet - enter URL and view the page
By Java Tip in forum Java TipReplies: 0Last Post: 03-10-2008, 02:38 PM -
Allowing only numeric values in a TextField
By Java Tip in forum Java TipReplies: 0Last Post: 03-01-2008, 10:08 PM -
enter data from an optic device
By bbq in forum Advanced JavaReplies: 2Last Post: 07-04-2007, 08:02 AM -
Javascript and enter button
By Eric in forum Advanced JavaReplies: 1Last Post: 06-11-2007, 09:39 PM
Bookmarks