SQL to determine whether a string contains numbers and letters.
Determine whether a letter is contained
select PATINDEX('%[A-Za-z]%', ‘ads23432')=0
(If a letter exists, result> 1)
Determines whether a number exists.
PATINDEX('%[0-9]%', ‘234sdf')=0
(If a number exists, result> 1)
How does SQL determine whether a string contains numbers?
I don't know what database you are using
Sqlserver
You can ,,,
Declare @ a varchar (10), @ B varchar (10), @ c VARCHAR (10) set @ a = 'sx1528' set @ B = '000000' SET @ c = 'sdfsdf 'select PATINDEX ('% [0-9] %', @ ), PATINDEX ('% [0-9] %', @ B), PATINDEX ('% [0-9] %', @ c)
In java, how can I determine whether a string contains letters or numbers?
For example:
Public static void main (String [] args ){
Boolean isDigit = false; // defines a boolean value to indicate whether a number is included.
Boolean isLetter = false; // defines a boolean value to indicate whether it contains letters.
String str = "aaasss8fff"; // assume there is a String
For (int I = 0; I <str. length (); I ++) {// looping string
If (Character. isDigit (str. charAt (I) {// use the method of judging numbers in the char packaging class to determine each Character
IsDigit = true;
}
If (Character. isLetter (str. charAt (I) {// use the method of determining letters in the char packaging class to determine each Character
IsLetter = true;
}
}
/* After the loop is completed
* If isDigit is true, it indicates that the string contains numbers. Otherwise, it does not contain
* If isLetter is true, it indicates that the string contains letters. Otherwise, it does not contain letters.
*/
System. out. println (isDigit );
System. out. println (isLetter );
}