Hi 🙂🖐
We know that validators are very important; they're used in many things like email, usernames, and passwords. In this post, I will share with you how to make validation by using a module called validators.
First, you need to install validators
pip install validators
[1] - URL Validation
import validators
print(validators.url('https://dev.to')) # True
validators.url
returns true' if the URL is valid. If not validated, it will return ValidationError
.
import validators
print(validators.url('https//dev.to'))
result
ValidationError(func=url, args={'value': 'https//dev.to'})
[2] - Email Validation
import validators
print(validators.email('test@test.com')) # True
validators.email
returns true' if Email is valid. If not validated, it will return ValidationError
.
[3] - Domain Validation
import validators
print(validators.domain('test.com')) # True
[4] - Card Numbers Validation
You can find Card Numbers to test from here : https://support.bluesnap.com/docs/test-credit-card-numbers
import validators
print(validators.card_number('6250941006528599')) # True
You can choose the card type that you want to validate. You have many types, like visa, Mastercard, Amex
Validate Visa card number
import validators
print(validators.visa('4263982640269299')) # True
Validate mastercard number
import validators
print(validators.mastercard('5425233430109903')) # True
Validate amex number
import validators
print(validators.amex('374245455400126')) # True
Now I will let you discover more. What validators can validate 🤗
Now we're done 🤗
Don't forget to like and follow 🙂
Support me on PayPal 🤗
https://www.paypal.com/paypalme/amr396