Created
May 11, 2015 01:51
-
-
Save TonyLadson/5da98cb2f3d73d621ae2 to your computer and use it in GitHub Desktop.
Is a value a valid new site number? i.e. 5 capital letters followed by 4 digits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isNewSiteNum <- function(x) { | |
# returns true if value is missing, or a site number i.e. 5 capitals follows by 4 digits | |
# otherwise returns false | |
if(is.na(x)) return(TRUE) | |
if(!is.character(x)) return(FALSE) | |
if(str_count(x) != 9) return(FALSE) | |
str_detect(x, "^[A-Z]{5}[:digit:]{4}") # 5 capitals followed by 4 digits | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment