in reply to Pattern matching fields with variable or NULL data
It sounds like you might want /^[\d\s]{0,3}$/, which works if the length is exactly 3 characters, each a space or a digit. Another approach might be to use more than just a pattern, if (length == 3 && /^\d*\s*$/), for instance, if you want the blanks to follow all the digits. Or if you want to extract the digits part and validate, you could do something like
But again, the first step is figuring out exactly what should and shouldn't match, and what you want to do when it doesn't. After that it's easy.if (length != 3 || !/^(\d*)\s*/){ die "invalid data"; } else { print "your number without spaces is '$1'\n"; }
|
|---|