OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Check if string contains numbers and plus sign in python

  • Thread starter Thread starter user25700860
  • Start date Start date
U

user25700860

Guest
I'm trying to build a reminder app and want to check whether the string the user gives contains only a plus symbol and numbers. Ideally it would start with a plus as this string will represent the country code and phone number to send the reminder to.

I tried the startswith() method along with the isdigit() method. However since I have to use and compare the two conditions it doesnt work seeing as the first character is a plus symbol and therefore not a digit.

I have also considered regex, however I can't find anywhere how to represent the + symbol in the string seeing as the + symbol actually means one or more occurences of a character as opposed to the plus symbol character itself.

Any help would be greatly appreciated
<p>I'm trying to build a reminder app and want to check whether the string the user gives contains only a plus symbol and numbers. Ideally it would start with a plus as this string will represent the country code and phone number to send the reminder to.</p>
<p>I tried the <code>startswith()</code> method along with the <code>isdigit()</code> method. However since I have to use and compare the two conditions it doesnt work seeing as the first character is a plus symbol and therefore not a digit.</p>
<p>I have also considered regex, however I can't find anywhere how to represent the <code>+</code> symbol in the string seeing as the <code>+</code> symbol actually means one or more occurences of a character as opposed to the plus symbol character itself.</p>
<p>Any help would be greatly appreciated</p>
 

Latest posts

Top