Home > database >  how to check if the value contains symbols
how to check if the value contains symbols

Time:01-04

i want ask to you ( in python)

how I can check if user enter symbols (!,@,#,$,%,^,&,*)

example if user enter this (1234g890) in var (number) I want compiler show ( number invalid try again )

number from 10 digit

I hope you understand what I mean

thankyou

CodePudding user response:

I believe, you have to use regular expression that is so simple. For example:

re.match(r'^([\s\d] )$', 'your text')

More information: tutorialspoint

CodePudding user response:

a naive approach would be to just create an array that contained the elements {(!,@,#,$,%,^,&,*} , then set up a for loop where you check to see if any element of the user input matches any element of the aforementioned list.

The better way would be to use regex to check if the string entered by the user contains a non alphanumeric characters, such as in this post.

https://stackoverflow.com/questions/29014462/python-regular-expression-to-check-alphanumeric

  •  Tags:  
  • Related