<commit_before>/**
 * Subdomain setup Screen.
 *
 * UI for subdomain setup.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

'use strict';

const subdomain = document.getElementById('subdomain');
const email = document.getElementById('email');
const createDomainButton = document.getElementById('create-domain-button');
// https://github.com/mozilla-iot/gateway/issues/159
//const skipButton = document.getElementById('skip-subdomain-button');
const errorMessage = document.getElementById('error-setup');

function displayMessage(errorMsg, type){
    errorMessage.innerHTML = errorMsg;
    errorMessage.classList.remove('hidden');
    if (type === 'message') {
        errorMessage.classList.remove('error');
        errorMessage.classList.add('message');
    } else {
        errorMessage.classList.remove('message');
        errorMessage.classList.add('error');
    }
}<commit_msg>Validate subdomains before calling /subscribe.<commit_after>/**
 * Subdomain setup Screen.
 *
 * UI for subdomain setup.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

'use strict';

const subdomain = document.getElementById('subdomain');
const email = document.getElementById('email');
const createDomainButton = document.getElementById('create-domain-button');
// https://github.com/mozilla-iot/gateway/issues/159
//const skipButton = document.getElementById('skip-subdomain-button');
const errorMessage = document.getElementById('error-setup');

function displayMessage(errorMsg, type){
    errorMessage.innerHTML = errorMsg;
    errorMessage.classList.remove('hidden');
    if (type === 'message') {
        errorMessage.classList.remove('error');
        errorMessage.classList.add('message');
    } else {
        errorMessage.classList.remove('message');
        errorMessage.classList.add('error');
    }
}

subdomain.addEventListener('input', function() {
    // Ensure that subdomain is valid:
    // - Contains only a-z, 0-9, and hyphens, but does not start or end with
    //   hyphen.
    // - Is not equal to "api", as that's reserved.
    const val = subdomain.value;
    const re = new RegExp(/^([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])$/, 'i');
    if (!re.test(val) || val === 'api') {
        createDomainButton.disabled = true;
    } else {
        createDomainButton.disabled = false;
    }
});
{'fraction_non_alphanumeric': 0.14323911382734913, 'fraction_numerical': 0.009167303284950344, 'mean_word_length': 3.627208480565371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6860502', 'n_tokens_mistral': 754, 'n_tokens_neox': 747, 'n_words': 198}