JavaScript library to validate various value-types of OpenStreetMap.
Useable in PlainJS, nodeJS and jQuery.
Install osmvalidation via npm:
npm install osmvalidation
var osmValidation = require('osmvalidation');
if(osmValidation.phone('+49 123 456-789')) {
// do stuff
console.log(osmValidation.msg);
}
Download osmValidation.js and include it before you use it.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>osmValidation</title>
</head>
<body>
<form>
<input type="url" />
<input type="submit" />
</form>
<script type="text/javascript" src="js/jQuery.js"></script>
<script type="text/javascript" src="js/osmValidation.js"></script>
<script type="text/javascript">
$('input[type=submit]').attr('disabled','disabled');
$('input[type=url]').onkeyup(function(){
if($(this).osmValidate()) {
$('input[type="submit"]').removeAttr('disabled');
} else {
$('input[type=submit]').attr('disabled','disabled');
}
});
</script>
</body>
</html>
Download osmValidation.js and include it before you use it.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>osmValidation</title>
</head>
<body>
<form>
<input id='url' type="url" />
<input id='submit' type="submit" />
</form>
<script type="text/javascript" src="js/jQuery.js"></script>
<script type="text/javascript" src="js/osmValidation.js"></script>
<script type="text/javascript">
document.getElementById('submit').onclick(function(){
if(osmValidation.url(document.getElementById('url').value) {
alert("valid");
}
});
</script>
</body>
</html>
phone(string)
Validate phonenumbersmail(string)
Validate mailaddressesurl(string)
Validate urlsfacebook(string)
Validate facebook IDgoogle(string)
Validate google plus IDtwitter(string)
Validate twitter IDwikipedia(string)
Validate wikipedia-Page tagwikidata(string)
Validate wikidata-ID
You can validate a givven String as parameter. The return is a boolean (false or true). If you want more informations, you can read msg
. This function returns a string with more informations about the validation. If you want to use your own error-messages: every msg
-string is a public string-constant of osmValidation. You can compare the return with the constant.
Available constants:
PLAIN_FLAG
empty string, default messagePHONE_EMERGENCY
phonenumber is a valid emergency numberPHONE_VALID
phonenumber is a valid international numberPHONE_INVALID
number is not a emergency number or an international phonenumber (+\d{1,4} \d+( \d+(-\d+)))MAIL_VALID
email is validMAIL_INVALID
email is invalidURL_PROTOCOLL_INVALID
URL has no or wrong protocoll. At this time, I allow only http or httpsURL_LOCAL_ADDRESS
URL to a local service is not usefulURL_HOST_INVALID
Host is not a ipv4- or ipv6-address and it has no fqdnURL_INVALID
URL seems brokenURL_VALID
URL is validFACEBOOK_ID_ONLY
correct facebook IDFACEBOOK_URL_VALID
correct facebook-page URLFACEBOOK_URL_INVALID
Neither a valid facebook ID nor a plain link (without parameter) to a pageTWITTER_ID_ONLY
correct twitter IDTWITTER_URL_VALID
correct twitter-page URLTWITTER_URL_INVALID
Neither a valid twitter ID nor a plain link (without parameter) to a pageGOOGLE_ID_ONLY
correct google IDGOOGLE_NAME_ONLY
correct google plus nameGOOGLE_URL_VALID
correct google-page URLGOOGLE_URL_INVALID
Neither a valid google ID, name nor a plain link (without parameter) to a pageWIKIPEDIA_INCLUDING_LANG
correct wikipedia page-name including language-tagWIKIPEDIA_EXCLUDING_LANG
correct wikipedia page-name without language-tagWIKIPEDIA_URL
correct wikipedia urlWIKIPEDIA_INVALID
Wikipedia-Tag not validWIKIDATA_VALID_TAG
correct wikidata tagWIKIDATA_INVALID
Wikidata-Tag not valid
There is a special jQuery-Function. You can validate an object by the function osmValidate()
. It use the type
- or data-type
-attribute of the object as identifier for the validation-function. It returns a boolean, NOT the object itself!