AppleScript名:AlphabetとNumericの混在かどうかを調べる |
— Created 2015-12-04 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aRes to chkMixtureOfNumericAndAlphabet("ABC") of me –> false set aRes to chkMixtureOfNumericAndAlphabet("123") of me –> false set aRes to chkMixtureOfNumericAndAlphabet("4f73vg1v") of me –Target –> true set aRes to chkMixtureOfNumericAndAlphabet("4f73vg1vあああ") of me –> false –数字とアルファベットの混在状態の時にtrueを返す on chkMixtureOfNumericAndAlphabet(checkString) set a0Res to chkAlphabetAndNumeric(checkString) of me set a1Res to chkNumeric(checkString) of me set a2Res to chkAlphabet(checkString) of me if {a0Res, a1Res, a2Res} = {true, false, false} then return true else return false end if end chkMixtureOfNumericAndAlphabet –数字のみかを調べて返す on chkNumeric(checkString) set digitCharSet to current application’s NSCharacterSet’s characterSetWithCharactersInString:"0123456789" set ret to my chkCompareString:checkString baseString:digitCharSet return ret as boolean end chkNumeric — アルファベットのみか調べて返す on chkAlphabet(checkString) set aStr to current application’s NSString’s stringWithString:checkString set allCharSet to current application’s NSMutableCharacterSet’s alloc()’s init() allCharSet’s addCharactersInRange:(current application’s NSMakeRange(ASCII number of "a", 26)) allCharSet’s addCharactersInRange:(current application’s NSMakeRange(ASCII number of "A", 26)) set aBool to my chkCompareString:aStr baseString:allCharSet return aBool as boolean end chkAlphabet — アルファベットと数字のみか調べて返す on chkAlphabetAndNumeric(checkString) set aStr to current application’s NSString’s stringWithString:checkString set allCharSet to current application’s NSMutableCharacterSet’s alloc()’s init() allCharSet’s addCharactersInRange:(current application’s NSMakeRange(ASCII number of "0", 10)) allCharSet’s addCharactersInRange:(current application’s NSMakeRange(ASCII number of "a", 26)) allCharSet’s addCharactersInRange:(current application’s NSMakeRange(ASCII number of "A", 26)) set aBool to my chkCompareString:aStr baseString:allCharSet return aBool as boolean end chkAlphabetAndNumeric on chkCompareString:checkString baseString:baseString set aScanner to current application’s NSScanner’s localizedScannerWithString:checkString aScanner’s setCharactersToBeSkipped:(missing value) aScanner’s scanCharactersFromSet:baseString intoString:(missing value) return (aScanner’s isAtEnd()) as boolean end chkCompareString:baseString: |
More from my site
(Visited 29 times, 1 visits today)