Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / String Manipulation

String validation

All topicsPractise exam questions
Knowledge organiser

String Manipulation

301.11d

Check patterns in text.

What you need to know

String methods like .isalpha(), .isdigit(), and .isalnum() check whether a string contains only certain types of characters. They return True or False.

Key points

  • .isalpha() — True if all letters
  • .isdigit() — True if all digits
  • .isalnum() — True if letters or digits only
  • Empty string returns False for all checks
  • Useful for input validation

Code examples

String validation
python
postcode = input("Postcode: ")
if postcode.isalnum() and len(postcode) >= 5:
    print("Valid format")
else:
    print("Invalid postcode")