@@ 1162-1177 (lines=16) @@ | ||
1159 | * |
|
1160 | * @throws InvalidArgumentException |
|
1161 | */ |
|
1162 | public static function alpha($value, $message = '') |
|
1163 | { |
|
1164 | static::string($value); |
|
1165 | ||
1166 | $locale = \setlocale(LC_CTYPE, 0); |
|
1167 | \setlocale(LC_CTYPE, 'C'); |
|
1168 | $valid = !\ctype_alpha($value); |
|
1169 | \setlocale(LC_CTYPE, $locale); |
|
1170 | ||
1171 | if ($valid) { |
|
1172 | static::reportInvalidArgument(\sprintf( |
|
1173 | $message ?: 'Expected a value to contain only letters. Got: %s', |
|
1174 | static::valueToString($value) |
|
1175 | )); |
|
1176 | } |
|
1177 | } |
|
1178 | ||
1179 | /** |
|
1180 | * @param mixed $value |
|
@@ 1185-1198 (lines=14) @@ | ||
1182 | * |
|
1183 | * @throws InvalidArgumentException |
|
1184 | */ |
|
1185 | public static function digits($value, $message = '') |
|
1186 | { |
|
1187 | $locale = \setlocale(LC_CTYPE, 0); |
|
1188 | \setlocale(LC_CTYPE, 'C'); |
|
1189 | $valid = !\ctype_digit($value); |
|
1190 | \setlocale(LC_CTYPE, $locale); |
|
1191 | ||
1192 | if ($valid) { |
|
1193 | static::reportInvalidArgument(\sprintf( |
|
1194 | $message ?: 'Expected a value to contain digits only. Got: %s', |
|
1195 | static::valueToString($value) |
|
1196 | )); |
|
1197 | } |
|
1198 | } |
|
1199 | ||
1200 | /** |
|
1201 | * @param mixed $value |
|
@@ 1206-1219 (lines=14) @@ | ||
1203 | * |
|
1204 | * @throws InvalidArgumentException |
|
1205 | */ |
|
1206 | public static function alnum($value, $message = '') |
|
1207 | { |
|
1208 | $locale = \setlocale(LC_CTYPE, 0); |
|
1209 | \setlocale(LC_CTYPE, 'C'); |
|
1210 | $valid = !\ctype_alnum($value); |
|
1211 | \setlocale(LC_CTYPE, $locale); |
|
1212 | ||
1213 | if ($valid) { |
|
1214 | static::reportInvalidArgument(\sprintf( |
|
1215 | $message ?: 'Expected a value to contain letters and digits only. Got: %s', |
|
1216 | static::valueToString($value) |
|
1217 | )); |
|
1218 | } |
|
1219 | } |
|
1220 | ||
1221 | /** |
|
1222 | * @param mixed $value |
|
@@ 1227-1240 (lines=14) @@ | ||
1224 | * |
|
1225 | * @throws InvalidArgumentException |
|
1226 | */ |
|
1227 | public static function lower($value, $message = '') |
|
1228 | { |
|
1229 | $locale = \setlocale(LC_CTYPE, 0); |
|
1230 | \setlocale(LC_CTYPE, 'C'); |
|
1231 | $valid = !\ctype_lower($value); |
|
1232 | \setlocale(LC_CTYPE, $locale); |
|
1233 | ||
1234 | if ($valid) { |
|
1235 | static::reportInvalidArgument(\sprintf( |
|
1236 | $message ?: 'Expected a value to contain lowercase characters only. Got: %s', |
|
1237 | static::valueToString($value) |
|
1238 | )); |
|
1239 | } |
|
1240 | } |
|
1241 | ||
1242 | /** |
|
1243 | * @param mixed $value |
|
@@ 1248-1261 (lines=14) @@ | ||
1245 | * |
|
1246 | * @throws InvalidArgumentException |
|
1247 | */ |
|
1248 | public static function upper($value, $message = '') |
|
1249 | { |
|
1250 | $locale = \setlocale(LC_CTYPE, 0); |
|
1251 | \setlocale(LC_CTYPE, 'C'); |
|
1252 | $valid = !\ctype_upper($value); |
|
1253 | \setlocale(LC_CTYPE, $locale); |
|
1254 | ||
1255 | if ($valid) { |
|
1256 | static::reportInvalidArgument(\sprintf( |
|
1257 | $message ?: 'Expected a value to contain uppercase characters only. Got: %s', |
|
1258 | static::valueToString($value) |
|
1259 | )); |
|
1260 | } |
|
1261 | } |
|
1262 | ||
1263 | /** |
|
1264 | * @param mixed $value |