diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 5c558f3bd6..5a148c826f 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -634,13 +634,15 @@ class DocType(Document): if not name: name = self.name + flags = {"flags": re.ASCII} if six.PY3 else {} + + # a DocType name should not start or end with an empty space + if re.match("^[ \t\n\r]+|[ \t\n\r]+$", name, **flags): + frappe.throw(_("DocType's name should not start or end with whitespace"), frappe.NameError) + # a DocType's name should not start with a number or underscore # and should only contain letters, numbers and underscore - if six.PY2: - is_a_valid_name = re.match("^(?![\W])[^\d_\s][\w ]+$", name) - else: - is_a_valid_name = re.match("^(?![\W])[^\d_\s][\w ]+$", name, flags = re.ASCII) - if not is_a_valid_name: + if not re.match("^(?![\W])[^\d_\s][\w ]+$", name, **flags): frappe.throw(_("DocType's name should start with a letter and it can only consist of letters, numbers, spaces and underscores"), frappe.NameError)