JTextField input validation
hi!
i have made a input form for my study project.in the form i want that user only can input numeric value.
another problem is that i want to make my textfield in such a type so that uesr can,t enter more than 20 character.
please tell me how can i solve these problems.
You are entering the same question with two different user names, i dont know what you are trying to achieve but i can guarantee you wont get a faster reply to your question if you free post like that. anyway i have answered part of your question to the other post.
Similar Messages
-
JTextField input check (errorDialog if invalid) & JComboBox Focus
I have a JTextfield which does an input check when the JTextField focus listener's focusLost method is called.
If I loose focus by clicking in on a JComboBox. The check gets done ok and focus is returned appropriately to the JTextField without any problems.
But if I try to show an errorDialog when the input is incorrect, the focus is returned to the JTextField without any problems, but the JComboBox remains highlighted as though it is still selected!
I am using sdk 1.4... on a linux box. does anyone know why this happens? and can anyone provide a clean solution to this?
Thanx,
Diego Paloschi.Hello Kleopatra,
Here's a little demo:
import javax.swing.*;
import javax.swing.event.*;
public class Debug extends JPanel
private JTextField t1;
private JComboBox c1;
private T1Verifier t1Verifier;
public void init()
t1 = new JTextField("20", 10);
t1.setInputVerifier(new T1Verifier(this));
String[] s = {"v1","v2","v3"};
c1 = new JComboBox(s);
add(t1);
add(c1);
public static void main(String s[])
Debug d = new Debug();
d.init();
JFrame f = new JFrame("Debug");
f.getContentPane().add(d);
f.setSize(300,300);
f.setVisible(true);
class T1Verifier extends InputVerifier
private Debug debug;
public T1Verifier(Debug debug)
this.debug = debug;
public boolean verify(JComponent input)
JTextField tf = (JTextField) input;
float value = Float.parseFloat(tf.getText());
boolean inRange = (value >= 0) && ( value <= 10);
return inRange;
public boolean shouldYieldFocus(JComponent input)
boolean valid = super.shouldYieldFocus(input);
JTextField tf = (JTextField) input;
if ( !valid ) {
tf.requestFocus();
JOptionPane d = new JOptionPane();
d.showMessageDialog(debug, "Out Of Range.", "ERROR" , JOptionPane.ERROR_MESSAGE);
return valid;
Even if u comment out the JOptionPane and just make the inputverifier return control to the textfield it still doesn't work! What am I missing? Or how would u doi it? -
Input validation in an OO-friendly fashion
Okay, so "input validation" may sound a bit like an issue for the security division of the forum, but I'm concerned with the most OO way to verify the inputs of users. The situation is that I have about five or six different blanks in a GUI (not that it matters) where a user can input something to change the GUI's model. The GUI's model is, itself, an interface and therefore supports pluggability.
Now, each of the inputs has potentially different "policies" or business rules for what can be entered. For example, one may be a date, etc. You guys know what I mean. Anyway, I know that I could just have some validation method for every field, but this doesn't seem to be very OO-esque.
I'd like to have some kind of an interface called "StringValidator" or something that would have a method "validate()," but I don't know how this would play out. Maybe I could have a map in my GUI model where the key is the field name and the associated value is an appropriate implementation of StringValidator? I don't know, though. Even though it would be easier to implement five specific methods, one for each field, I'd rather not.
If I use some kind of StringValidator, maybe I could require a method that returns an array of Strings with all illegal forms, but then again, that's bad form...
I really just don't know.
So, in summary, my two questions are as follows:
1. What is the best way to implement an OO, easily scalable way to validate Strings in my app?
2. How do I protect against things like SQL statements, HTML scripts, etc.? I know I should (in many cases), but I don't know how to.
Thanks for any help, and for wading through that description.
theAmerican
PS I just remembered something about some Scanner class or something. Maybe that would help?It depends quite what you're doing; if you're working with a db then using prepared statements would handle all the escaping for you, but if you allow the users to input raw SQL then you can't realistically stop them from screwing things up.
Similarly if you're having the users create html somewhere, then the more flexibility there is the harder it is to control. You don't have to worry about scripting if you're just using JLabel to render the html as it doesn't support it; if you're creating a web UI then you may have to.
Pete -
MM41/MM42/(MM43) - Sales view: How to add own input validation for CALP-END
Hello.
I am looking for an easy way, if any to create an own input validation for a certain field in the article master on the sales view tab. In addition to any standard input validation I would a like to add an own validation (for CALP-ENDPR) depending on the input.
How can that be achieved in the easiest and proper manner - in general and for the specific case?
There are no screen exits etc. here, if I am correct.
Any ideas?
Thanks.
C.N.Hi,
Please refer the below link.
This is for MM01. I understand that you are into Retail system. Hope the same processing logic can be done in your scenario also.
saptechnical(dot)com(slash)Tutorials(slash)ExitsBADIs(slash)MM(slash)MM01(dot)htm
Replace the bracket words with the correct symbols.
With Regards,
Sumodh.P -
Input validations using bsp code
hai all,
i want to check user input whether he/she entered correct values r not, i know how to do using javascript.
but i need to do the same without using javascript.. is there any way
leoizNo, this was not a joke, but it would be possible theoretically.
Doing a quick search on Google got me this nice link:
http://www.permadi.com/tutorial/flashjscommand/
It shows an example of Flash interacting with JavaScript, hence proving the possibility.
As for really using Flash/ActionScript for input validation ...
If you are thinking about just including a little Flash-Validation for input fields - why do it with Flash if you can use JavaScript?
And if your page is a Flash-Page anyway, well, you would not have to go back to HTML input fields, as you work within your Flash applet.
Maybe you have a specific situation I didn't think of yet.
Max -
How do I return to the top of a form when input validation fails?
I have a form that I am using spry input validation that I
would like the user to be returned to the top of the page when
validation fails. If that can't be done somewhat easily, can I have
a message appear next to the submit button that says "Errors found.
The field(s) marked in red need to be corrected" when there are any
errors that prevent the form from submitting.The break statement in Java is similar to last in Perl.
The continue statement in Java is similar to next in Perl. -
[solved][C] input validation with strtod()
I'm using strtod() in an RPN implementation, and I'm working on input validation. As per strtod(3), I've written the following conditional to catch input overflow.
errno = 0;
op1 = strtod(token, &endPtr);
if ((errno == ERANGE && (op1 == HUGE_VALF || op1 == HUGE_VALL)) || (errno != 0 && op1 == 0)) {
printf("Error: Input overflow.\n");
clearstack();
return 1;
Except that when I enter something that would definitely overflow, this conditional is never entered. Furthermore, errno is never set. What am I missing?
A link to the full code can be found here
Last edited by falconindy (2010-04-13 17:49:15)tavianator wrote:
Well the first wrong thing I see is that you should really test if fabs(op1) is HUGE_VAL{F,L}.
The second thing is, why so complicated a test? errno != 0 should be all you need.
Fair enough. This is the first time I'm really dealing with floating point ops in C.
tavianator wrote:The third thing is, if errno is really not being set, are you sure you're really overflowing? doubles go up to about
1.8e308 on most arches.
Huh... wouldn't an unsigned double be, at most, 2^128 - 1 and more likely 2^64 - 1? I'm dealing with signed, so its then half that. Sure enough, sizeof(double) returns 8.
Also, this is what made me think I'm hitting overflow.
> 111111111111111111111111111111111111111111111111111111111111111111111111111111111111 1 *
= 111111111111111105547424803279259724863245197668615715838829352563602489955831513088.000
>
Hmm. If I go even further, I eventually do hit an overflow error. However, that still leaves me a little baffled as to the results above. Is this a result of the decimal precision inherent in a double? -
Element Input Validation - Table Values
Hi All,
Forum newbie.
Can anyone tell me if its possible to do an Element Input Validation that is using table values?
eg.
This was my thinking -
DEFAULT FOR TableLower IS 0
DEFAULT FOR TableUpper IS 0
INPUTS ARE entry_value (text)
entry = TO_NUM(entry_value)
Lower = TO_NUM(GET_TABLE_VALUE('Table Selected', 'Level', TableLower))
Upper = TO_NUM(GET_TABLE_VALUE('Table Selected', 'Level', TableUpper))
IF entry > Upper OR entry < Lower THEN
formula_status = 'E'
formula_message = 'Entry Value Must Be In The Table Range 1'
ELSE
formula_status = 's'
RETURN formula_status, formula_message
Any help would be very much appreciated.
DeanHello,
It is possible to use GET_TABLE_VALUE function in element input validation.
Thanks,
Sudhakar -
How to do input validation in BDC's?
hai,
I am Rajesh, I want to know how and where to write input validation code in BDC's. Please help me on this.
Thanking youHi and welcome
all key-fields (and fields with a check-table) are checked by SAP-standard in your called transaction in BDC too.
if you want to validate additional:
1)load you data from flat file into itab
2)check fields:
-against checktable
-format (date,currency)
-value
A.
pls reward usful answers
Message was edited by: Andreas Mann -
Check validation of JTextField input
In my code, I have a JTextField which can only input 0 or 1, I want to check if the input is empty first then if it is 0 or 1. The following is my code:
if (myJTextField.getText()==""){
return "empty";
else if (myJTextField.getText()!="0" && myJTextField.getText() != "1")
return "not 0 or 1";
but it does not work, where is the problem?
Thanks,if (myJTextField.getText().length() > 0){
try {
int i =
int i = Integer.parseInt(myJTextField.getText() );
if((i != 0) || (i != 1)) msg = "wrong
g = "wrong number";
else processIt;
catch etc...I think the logic operator should be && instead of ||? -
Date and Time Input Validation
Anyone know a good way to validate date and time that a user is entering on the screen. Our users want to enter AM and PM time vs. Military time.
Also, since Input fields don't have an "onBlur" command, what are other companies using in java script.What type of DATE/TIME validation are you looking for?
If you want to validate the format you could simply set the type to date/time and enable the dovalidate attribute to "TRUE".
for getting onBlur, onChange, etc for your input field you can use bsp:findandreplace.
<%
tmp_string =`<input onBlur="javascript:yourjsfunction();"`.
%>
<bsp:findAndReplace find = "<input"
replace = "<%= tmp_string %>" >
<htmlb:inputField id = "myInputField2"
value = "12345"
alignment = "left" />
</bsp:findAndReplace>
(courtesy Ulli Hoffmann)
Hope this helps.
Regards
Raja -
Hi All,
I'm using BEx WAD to call a query that allows me to see cost center information according to user authorizations thru the Portal. However, if I type an invalid entry then the application returns everything, including nodes that the user is not supposed to be authorized to see. How do I resolve this? Can I do it thru input data validation? Is there another simpler solution?
Thanks
Marshall.Marshall,
How are you providing authorization to Query?
Nagesh Ganisetti. -
hi,
My program require 4 inputs. One parameter(obligatory) and remaining are select-options.I am validating all the fields.
When I enter wrong value for obligatory field remaining select-options are being disabled(grayed) untill I click on them.
How to enable them automatically.
Please help me.- Put the parameters/select-options in a [SELECTION-SCREEN BLOCK|http://help.sap.com/abapdocu/en/ABAPSELECTION-SCREEN_BLOCK.htm].
- Execute you check in a [AT SELECTION-SCREEN|http://help.sap.com/abapdocu/en/ABAPAT_SELECTION-SCREEN.htm] [ON BLOCK|http://help.sap.com/abapdocu/en/ABAPAT_SELECTION-SCREEN_EVENTS.htm#!ABAP_ALTERNATIVE_4@4@] blo.
When the error will be sent, the whole block keeps editable and the cursor is at the first field of the block.
Regards,
Raymond -
Hy to all,
we are taking purchase order no from user and want to validate the user input.
Can some one tell me how to implement validation....
thanks in advanceHi,
Pls check things like
http://www.w3schools.com/js/js_form_validation.asp
http://www.developertutorials.com/tutorials/javascript/javascript-form-validation-correction-050412/page1.html
http://www.yourhtmlsource.com/javascript/formvalidation.html
Eddy -
Input Validator : FocusLost event handling
I am new to working with FocusListener and I am trying to use it validate the input of a textfield to be an integer.
This seems like a seemingly simple thing to do, but I am getting errors.
Here is a portion of the code where I make the textfield and assign it to a focus listener.
InputValidator i = new InputValidator();
resolutionlabel = new JLabel("Resolution: ");
p.add(resolutionlabel);
resolutiontextbox = new JTextField("3200");
resolutionlabel.setLabelFor(resolutiontextbox);
resolutiontextbox.addFocusListener(i);
p.add(resolutiontextbox);Here is the important parts of the focus listener code:
public class InputValidator extends FocusAdapter
public InputValidator()
public void focusLost(FocusEvent event)
validate((TextField)(event.getSource()));
private void validate(TextField field)
}The error I am getting is on the line where I call the validate function and is listed as :
java.lang.ClassCastException: javax.swing.JTextFieldthis might be an alternative way - it won't accept non-digit characters
import javax.swing.*;
import java.awt.*;
import javax.swing.text.*;
class Testing extends JFrame
public Testing()
setLocation(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
JTextField tf = new JTextField(new NumberLimiter(),"3200",10);
jp.add(tf);
getContentPane().add(jp);
pack();
class NumberLimiter extends PlainDocument
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
char[] characters = str.toCharArray();
for(int x = 0, y = characters.length; x < y; x++)
if(Character.isDigit(characters[x]) == false)
java.awt.Toolkit.getDefaultToolkit().beep();
return;
super.insertString(offs, str, a);
public static void main(String[] args){new Testing().setVisible(true);}
}
Maybe you are looking for
-
Upgrade CUPS from 8.5 to 9.0 ? Is it possible ?
Hi, is it possible to upgrade directly CUPS from 8.5 to 9.0. when i do it, i get the following error : Error encountered: Version mismatch. Please switch versions on the publisher and try again after checking logs : I found that : ERROR: The CUCM
-
I've lately been having this issue with my iPhone. When I go to transfer a newly purchased album or song from my iTunes library on my Macbook Pro to my iPhone 5 my ENTIRE LIBRARY is transferred to my iPhone. I have it checked so I can manually manage
-
Just did a software update, and all that my Macbook Pro does is just beep. Does anyone have any solutions?
-
Hp laserjet p1102 and time capsule
my hp laserjet P1102 is working fine with my regular wireless netgear router, but wouldn't connect to my time capsule. the blue light is just flashing and the printer doesn't show up on the network. i tried everything on the timecapsule manual, every
-
File path control - browse button colour/color
I can't change the colour of the browse button on a file path control. I'm using LV 8.5, but I think I have the same problem on 7.1 Is the only way to change the colour to customise the control? Every other part of it seems to take colours from the t