diff --git a/share/qtcreator/templates/wizards/classes/cpp/wizard.json b/share/qtcreator/templates/wizards/classes/cpp/wizard.json
index 57d8252f1abea2db9a2a7e240409fa7c7104bc53..dd2915cbfe35fb7938b58727e5485e64142afbdb 100644
--- a/share/qtcreator/templates/wizards/classes/cpp/wizard.json
+++ b/share/qtcreator/templates/wizards/classes/cpp/wizard.json
@@ -33,7 +33,8 @@
                     "name": "Class",
                     "trDisplayName": "Class name:",
                     "mandatory": true,
-                    "type": "LineEdit"
+                    "type": "LineEdit",
+                    "data": { "validator": "(?:(?:[a-zA-Z_][a-zA-Z_0-9]*::)+[a-zA-Z_][a-zA-Z_0-9]*|)" }
                 },
                 {
                     "name": "BaseCB",
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
index 744b64f1fa9944e4a92f15a9fe83375bcdff8574..fd9d6128d8735f52df8dd7497eb065fc789f3f69 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
@@ -46,6 +46,8 @@
 #include <QFormLayout>
 #include <QLabel>
 #include <QLineEdit>
+#include <QRegularExpression>
+#include <QRegularExpressionValidator>
 #include <QTextEdit>
 #include <QVariant>
 #include <QVariantMap>
@@ -263,9 +265,14 @@ QWidget *JsonFieldPage::SpacerField::widget(const QString &displayName)
 // --------------------------------------------------------------------
 
 JsonFieldPage::LineEditField::LineEditField() :
-    m_isModified(false)
+    m_validatorRegExp(0), m_isModified(false)
 { }
 
+JsonFieldPage::LineEditField::~LineEditField()
+{
+    delete m_validatorRegExp;
+}
+
 bool JsonFieldPage::LineEditField::parseData(const QVariant &data, QString *errorMessage)
 {
     if (data.isNull())
@@ -282,6 +289,18 @@ bool JsonFieldPage::LineEditField::parseData(const QVariant &data, QString *erro
     m_defaultText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trText")).toString());
     m_disabledText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trDisabledText")).toString());
     m_placeholderText = JsonWizardFactory::localizedString(tmp.value(QLatin1String("trPlaceholder")).toString());
+    QString pattern = tmp.value(QLatin1String("validator")).toString();
+    if (!pattern.isEmpty()) {
+        m_validatorRegExp = new QRegularExpression(pattern);
+        if (!m_validatorRegExp->isValid()) {
+            *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
+                                                        "Invalid regular expression \"%1\" in \"validator\".")
+                    .arg(pattern);
+            delete m_validatorRegExp;
+            m_validatorRegExp = 0;
+            return false;
+        }
+    }
 
     return true;
 }
@@ -293,6 +312,9 @@ QWidget *JsonFieldPage::LineEditField::widget(const QString &displayName)
     QLineEdit *w = new QLineEdit;
     connect(w, &QLineEdit::textEdited, [this](){ m_isModified = true; });
 
+    if (m_validatorRegExp)
+        w->setValidator(new QRegularExpressionValidator(*m_validatorRegExp, w));
+
     m_widget = w;
     return m_widget;
 }
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h
index 770c34e925b6955f9d40f8c0904b2bb220a8b681..591f9b094107bd9e2e40e3f20690c32229c62c50 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h
+++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.h
@@ -40,6 +40,7 @@ QT_BEGIN_NAMESPACE
 class QFormLayout;
 class QLabel;
 class QLineEdit;
+class QRegularExpression;
 class QTextEdit;
 QT_END_NAMESPACE
 
@@ -127,6 +128,7 @@ public:
     {
     public:
         LineEditField();
+        ~LineEditField();
 
     private:
         bool parseData(const QVariant &data, QString *errorMessage);
@@ -140,6 +142,7 @@ public:
         QString m_placeholderText;
         QString m_defaultText;
         QString m_disabledText;
+        QRegularExpression *m_validatorRegExp;
 
         bool m_isModified;
         mutable QString m_currentText;