• Post Reply Bookmark Topic Watch Topic
  • New Topic

string digit testing  RSS feed

 
kennith stomps
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on line 12 I receive the error: Syntax error, insert ") Statement" to complete BlockStatements
I am trying to test the number of digits contained in the string
I can not think of any other ways of going about this.

 
Pete Letkeman
Ranch Foreman
Posts: 833
25
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code block is incomplete

You have three ( and only two ). If you put another ) after before the { on line 12 then you will get past this error.
 
Pete Letkeman
Ranch Foreman
Posts: 833
25
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not too sure how strong your regular expression knowledge is, but I do suspect that what you are trying could be done without loops and a correctly crafted regular expression.
I have found this site http://www.regexlib.com/ to be a good resource for regular expressions and they have a online regular expression tester.
 
kennith stomps
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is their a way to do this without regex,
 
kennith stomps
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in regards to checking whether or not the password contains a special character
 
Pete Letkeman
Ranch Foreman
Posts: 833
25
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kennith stomps wrote:is their a way to do this without regex, in regards to checking whether or not the password contains a special character

I'm sure that there is and that would require loops and if like you have started doing.
But, I'm not too sure what the exact code is.
 
Liutauras Vilda
Marshal
Posts: 4804
330
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Please indent and format your code.
2. Please remove useless comments.
3. Please re-post code after accomplish 1 and 2.
 
kennith stomps
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about something like this?
if password contains any special character, terminate.
error is: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
[]
//if password
if (password.contains("[^\w\.\,!""$%^&*\(\)-_+=::@']"){
}
[/code]
 
kennith stomps
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line 24 is giving me the error: This method must return a result of type boolean

this is the only route I can think of checking whether the string contains any special characters, by returning a boolean, however my boolean is not working? why is this?

 
Knute Snortum
Sheriff
Posts: 4204
122
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if (password.contains("[^\w\.\,!""$%^&*\(\)-_+=::@']"){

This is a common mistake when coding regexes with Strings.  We forget that Strings can have escape characters.  So for instance, "\w" isn't a valid escape sequence in a String.  If we want a regex of \w in a String, we have to type "\\w" to escape the backslash.
 
Knute Snortum
Sheriff
Posts: 4204
122
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kennith stomps wrote:line 24 is giving me the error: This method must return a result of type boolean

this is the only route I can think of checking whether the string contains any special characters, by returning a boolean, however my boolean is not working? why is this?

Is your code returning a boolean in all cases?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!