why registration password only accepts # symbol? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
private Boolean validatePass() {
String val = pass.getEditText().getText().toString().trim();
String passwordVal = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!#$%^&*-]).{8,}$";
if (val.isEmpty()) {
pass.setError("*Required");
return false;
} else if (!val.matches(passwordVal)) {
pass.setError("Invalid Password");
return false;
} else {
pass.setError(null);
return true;
}
}
I used this code for password Validation, what's wrong with this?

As per what your regex code is it should satisfy for all the symbols mentioned there #,?,!,#,$,%,^,&,*,- it will fail if you use symbols other than these like _,+,~,`

Related

What does return "" mean? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
for (int i = 0; i < alist.size(); i++) {
if ( alist.get(i).average() == d ) {
return alist.get(i).getCountry();
}
}
return "";
}
I need to return the name of the country which is in alist.get(i).getCountry(), but when I end the body with that it will say
error: missing {
When I put return "" it doesn't have an error.
What does return "" mean?
return ""; just returns an empty string.
If you put alist.get(i).getCountry() outside of the for loop it will not make sense. (I'm assuming that's what you mean by "end the body with that.") It depends on i, which only exists in the loop.
It's tough to see why you're getting that error without seeing more of your code.

"startsWith" method [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
It's showing unknown method "startsWith"
If it's the incorrect way then please tell the correct way
EditText editTxt = (EditText) findViewById(R.id.a);
WebView webv = (WebView) findViewById(R.id.b);
if (editTxt.startsWith("http://"){
webv.loadUrl(editTxt.getText().toString());
}else{
webv.loadUrl("http://" + editTxt.getText().toString());
}
startsWith is method of String, you need to convert to String first:
String editTxtString = editTxt.getText().toString();
if (editTxtString .startsWith("http://")) {
webv.loadUrl(editTxtString);
} else {
webv.loadUrl("http://" + editTxtString);
}
Or one liner:
webv.loadUrl(editTxtString .startsWith("http://")? editTxtString: "http://" + editTxtString);
Is editText is string class? You post to little code but try thisif editText is not String class:
if (editTxt.getText().toString().startsWith("http://"){
webv.loadUrl(editTxt.getText().toString());
}else{
webv.loadUrl("http://" + editTxt.getText().toString());
}

How to get image from user in java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is there any way that I can input image at runtime using java? Like we ask user to input Integer and use the function input.nextInt().
Also I want to put restriction that input image is only of jpeg type ?
public static Boolean isJPEG(File filename) throws IOException {
DataInputStream ins = new DataInputStream(new BufferedInputStream(new FileInputStream(filename)));
try {
if (ins.readInt() == 0xffd8ffe0) {
return true;
} else {
return false;
}
} finally {
ins.close();
}
}

How to split a string before a specific character (so that the delimiter character is in the second part of the result) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
if I have
String a = "abc,,,";
what should I do to get
result[0].equals("abc");
result[1].equals(",,,");
The most elementary way is this:
final int pos = a.indexOf(',');
if( pos == -1 ) { // character not found, handle this case somehow }
String [] result = new String [2];
result[0]=a.substring(0, pos);
result[1]=a.substring(pos);

How to extract the substring from the String using StringTokenizer in Java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Following is the source string. And I need to extract the values from this string.
String str = "sid=2096349073&name=Sam_Michaels";
For example, I should get the token value as "2096349073" and next token should be "Sam_Michaels"
You don't need StringTokenizer. This will work same
public class NewClass {
public static void main(String[] args) {
String str = "sid=2096349073&name=Sam_Michaels";
String id=str.substring(1+str.indexOf("="),str.indexOf("&"));
String name=str.substring(1+str.lastIndexOf("="));
System.out.println("Id is : "+id);
System.out.println("name is : "+name);
}
}

Categories