This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

string digit testing  RSS feed

 
Ranch Hand
Posts: 273
  • 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.

 
Saloon Keeper
Posts: 1844
80
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
Saloon Keeper
Posts: 1844
80
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: 273
  • 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: 273
  • 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
Saloon Keeper
Posts: 1844
80
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.
 
Marshal
Posts: 6008
415
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: 273
  • 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: 273
  • 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?

 
Sheriff
Posts: 5112
138
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: 5112
138
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!