![]() |
#1 |
Registered User
Join Date: Jul 2011
Posts: 262
|
Check size of input
How would i go about checking the length of the input the user has put into a text field...
What I want to be able to do is check if what they have entered is between 3 and 20 characters long.. then if its less than 3 or more than 20 use an alert to tell them they must enter a username between 3 and 20 characters. Thanks |
![]() |
![]() |
![]() |
#2 |
Moderator
Join Date: Sep 2011
Location: INDIA
Posts: 250
|
use text.length property
|
![]() |
![]() |
![]() |
#3 |
Registered User
Join Date: Jul 2011
Posts: 49
|
public static void main(String[] args) {
Scanner scan = new Scanner(System.in); String x; System.out.print("Input text -> "); x = scan.nextLine(); while(x.length() < 3 || x.length() >20) { System.out.print("Word length must be between 3 and 20 -> "); x = scan.nextLine(); } System.out.println("Text length: " + x.length()); } Something like this i asume? |
![]() |
![]() |
![]() |
#4 |
Registered User
Join Date: Nov 2011
Posts: 48
|
You have to check variable length or textbox character length right, than you get text from text box and store it in variable and check its length properties, easily you will find out length of text.
__________________
people finder |
![]() |
![]() |
![]() |
#5 |
Registered User
Join Date: Dec 2011
Posts: 217
|
We can check the length of the input easily be using some syntax like
text.length. |
![]() |
![]() |
![]() |
#6 |
Registered User
Join Date: Sep 2011
Posts: 113
|
hey i agree with you my friend.
|
![]() |
![]() |
![]() |
#7 | |
Registered User
Join Date: Nov 2013
Posts: 92
|
Quote:
|
|
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|