Idcheck identifier Legality check

Source: Internet
Author: User

#!/usr/bin/env python#--*--coding:utf-8--*--"""identifier legality check, first to start with a letter or underscore, followed by letters, underscores or numbers This example only check the length is greater than or equal to 2 of the indicator"""ImportStringalphas= String.letters +'_'Nums=string.digitsdefmenu ():Print 'Welcome to the Identifier Checker v1.0'    Print 'Testees must is at least 2 chars long.'    #myinput = raw_input (' Identifier to test?\n ')defRunidchk (myinput):ifLen (myinput) > 1:#whether the length of the interpretation is greater than 2        ifMYINPUT[0] not inchAlphas:#whether the first letter is a letter or an underscore            Print "Invalid:first symbol must be alphabetic"        Else:              forOthercharinchMyinput[1:]:                ifOtherchar not inchAlphas +Nums:Print "invalid:remaining symbols must be alphabetic"                     Break                Else:                    Print "okay as an Identifier"if __name__=='__main__':     whileTrue:menu () runidchk (Raw_input ('Identifier to test?\n'))

Running Result:

Kevins-macbook-pro:chapter06 kevin$ python idcheck.py Welcome to the Identifier Checker V1.0testees must is at least 2 cha RS Long. Identifier to Test?__hellookay as a identifierokay as an identifierokay as an identifierokay as a identifierokay as an I Dentifierokay as an identifierwelcome to the Identifier Checker V1.0testees must is at least 2 chars long. Identifier to Test?333invalid:first symbol must be alphabetic

Idcheck identifier Legality check

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.