Skip to content

Commit

Permalink
Merge pull request #13 from JacksonTsai/master
Browse files Browse the repository at this point in the history
feat(formly): add validate altitude
  • Loading branch information
zack9433 authored Apr 3, 2019
2 parents 80756a1 + 2b0245a commit f3296d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/component/formly.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,23 @@ const types = [
}
}
},
{
name: 'altitude',
defaultOptions: {
templateOptions: {
label: 'FORM_LABEL_ALTITUDE'
},
validators: {
longitude: {
expression: function($viewValue, $modelValue) {
const value = $modelValue || $viewValue;
return !value || validateAltitude(value);
},
message: '"FORM_ALTITUDE_ERROR_MSG"'
}
}
}
},
{
name: 'password',
template: `<input type="password" ng-model="model[options.key]">`,
Expand Down Expand Up @@ -642,6 +659,10 @@ function validateLongitude(value) {
return /^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/.test(value);
}

function validateAltitude(value) {
return /^[+-]?(?:[1-9][0-9]{0,3}(?:\.\d{1,9})?|10000)$/.test(value);
}

function validatePassword(value) {
return /^(?=.*\d)(?=.*[a-zA-Z]).{6,100}$/.test(value);
}
Expand Down
2 changes: 2 additions & 0 deletions src/component/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"FORM_LABEL_IP": "IP",
"FORM_LABEL_LATITUDE": "Latitude",
"FORM_LABEL_LONGITUDE": "Longitude",
"FORM_LABEL_ALTITUDE": "Altitude",
"FORM_LABEL_PASSWORD": "Password",
"FORM_LABEL_NAME": "Name",
"FORM_LABEL_HOSTNAME": "Hostname",
Expand All @@ -40,6 +41,7 @@
"FORM_PASSWORD_ERROR_MSG": "Allowed chars include A-Z,a-z,0-9 and length must between 6 and 100.",
"FORM_LONGITUDE_ERROR_MSG": "Invalid longitude format",
"FORM_LATITUDE_ERROR_MSG": "Invalid latitude format",
"FORM_ALTITUDE_ERROR_MSG": "Invalid altitude format(-10000~10000)",
"FORM_IP_ERROR_MSG": "Invalid IP format",
"FORM_EMAIL_ERROR_MSG": "Invalid email format",
"FORM_URL_ERROR_MSG": "Invalid URL format",
Expand Down
2 changes: 2 additions & 0 deletions src/component/lang/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"FORM_LABEL_IP": "網路位址",
"FORM_LABEL_LATITUDE": "緯度",
"FORM_LABEL_LONGITUDE": "經度",
"FORM_LABEL_ALTITUDE": "海拔",
"FORM_LABEL_PASSWORD": "密碼",
"FORM_LABEL_NAME": "名稱",
"FORM_LABEL_HOSTNAME": "主機名稱",
Expand All @@ -40,6 +41,7 @@
"FORM_PASSWORD_ERROR_MSG": "字元只允許 A-Z,a-z,0-9 並且長度在6-100之間",
"FORM_LONGITUDE_ERROR_MSG": "經度格式錯誤",
"FORM_LATITUDE_ERROR_MSG": "緯度格式錯誤",
"FORM_ALTITUDE_ERROR_MSG": "海拔格式錯誤(-10000~10000)",
"FORM_IP_ERROR_MSG": "IP 格式錯誤",
"FORM_EMAIL_ERROR_MSG": "電子郵件格式錯誤",
"FORM_URL_ERROR_MSG": "URL 格式錯誤",
Expand Down

0 comments on commit f3296d8

Please sign in to comment.