Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function validateFormat(text) {
- // Do stuff
- }
- validateFormat("blab abalaba $something$ avava $affo$") -> true
- validateFormat("blab abalaba $something$ avava $ affo$") -> false because of the white space
- validateFormat("blab abalaba $1so3mething$ avava $affo$") -> false because of the numbers
- validateFormat("blab abalaba $something") -> false because of unclosed placeholder
- // delete all valid placeholders
- text = text.replace(/$[a-z]+$/gi, "");
- // are there any "$" left?
- if (text.search(/$/) != -1) {
- return false;
- }
- return true;
- matches = text.match(/$[a-z]+$|$/gi);
- if (matches) {
- for (var i = 0; i < matches.length; i++) {
- if (matches[i] == '$') { return false };
- }
- }
- return true;
- text.match(/$/g).length/2 == text.match(/$[a-z]+$/g).length
Add Comment
Please, Sign In to add comment