SQL to determine whether a string contains numbers and letters.

Source: Internet
Author: User

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 );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.